Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the four typical SQL Server codes in the database?

Shulou Source: shulou.com Published: 2022-06-02 09:01:58 10月03日 Update

This article will explain in detail what the four typical SQL Server codes in the database are, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Today, let's take a look at four typical types of code in SQL Server.

DataReader of ASP.NET database operation code

Function: DataReader reading class, performing "forward-only" reading of data.

Read-only, forward-only data stream. Because there is only one row of data in memory at a time, using DataReader can improve application performance and reduce system overhead. It also provides an unbuffered data stream that enables process logic to effectively process the results returned from the data source sequentially. Because data is not cached in memory, DataReader is an appropriate choice when retrieving large amounts of data.

String strConn= "uid= account; pwd= password; database= Database; server= Server"; SqlConnection ConnSql=new SqlConnection (strConn); ConnSql.Open (); / / Open database string strSQL= "SELECT * FROM Table name 1"; SqlCommand cmd = new SqlCommand (strSQL,ConnSql); SqlDataReader dr=cmd.ExecuteReader (); Read (); dr.Close (); Close (); / / close the database

DataSet of ASP.NET database operation code

Function: DataSet,DataAdapter reads data.

String strConn= "uid= account; pwd= password; database= Database; server= Server"; SqlConnection ConnSql=new SqlConnection (strConn); ConnSql.Open (); string strSQL= "SELECT * FROM Table name 1"; SqlDataAdapter da=new SqlDataAdapter (strSQL,ConnSql); DataSet ds=new DataSet (); Fill (ds, "Custom Virtual Table name"); Close (); / / close the database

ExecuteNonQuery of ASP.NET database operation code

Function: use ExecuteNonQuery to insert, update and delete data.

Q: what is ExecuteNonQuery?

Answer: in ADO.NET, the ExecuteNonQuery method is used to execute commands that do not need to return results, such as insert, delete, and update.

String strConn= "uid= account; pwd= password; database= Database; server= Server"; SqlConnection ConnSql=new SqlConnection (strConn); ConnSql.Open (); string strSQL= "INSERT INTO Table name 1, UPDATE Table name 1 SET, DELETE FROM Table name 1"; SqlCommand cmd=new SqlCommand (strSQL,ConnSql); ExecuteNonQuery (); Close (); / / close the database

ExecuteScalar of ASP.NET database operation code

Function: use ExecuteScalar statistics.

Q: what is ExecuteScalar?

Answer: the ExecuteScalar method can return a single value, such as the aggregate function of a SQL statement, such as the sum, the total number of rows, and so on.

String strConn= "uid= account; pwd= password; database= Database; server= Server"; SqlConnection ConnSql=new SqlConnection (strConn); ConnSql.Open (); / / Open database string strSQL= "SELECT COUNT (*) FROM Table name 1"; SqlCommand cmd = new SqlCommand (strSQL,ConnSql); int intNum= (int) cmd.ExecuteScalar (); Close () / / closing the database is enough about what the four typical SQL Server codes in the database are. I hope the above content can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Tags: Data database code function password server account service typical data flow memory content article method more knowledge article result update good Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi OPPO Reno macOS Shulou Information