Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report