ASP. NET database operationsCodeDatareader
Function: datareader reading class, which reads data only forward.
Read-only and inbound data streams. Because there is only one row of data in the memory each time, you can use datareader to improve the applicationProgramPerformance and reduce system overhead. It also provides an unbuffered data stream that enables the process logic to effectively process the results returned from the data source in order. Because the data is not cached in the memory, datareader is an appropriate choice when retrieving a large amount of data.
String strconn = "uid = Account; Pwd = password; database = database; server = server ";
Sqlconnection connsql = new sqlconnection (strconn );
Connsql. open (); // open the 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 for ASP. NET database operation code
Purpose: DataSet and dataadapter read 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 for ASP. NET database operation code
Purpose: executenonquery is used to insert, update, and delete data.
Q: What is executenonquery?
A: In ADO. net, the executenonquery method is used to execute commands that do not need to return results, such as insert, delete, and update operations.
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 for ASP. NET database operation code
Purpose: Use executescalar statistics.
Q: What is executescalar?
A: The executescalar method returns an aggregate function of a single value, such as sum and total number of rows.
String strconn = "uid = Account; Pwd = password; database = database; server = server ";
Sqlconnection connsql = new sqlconnection (strconn );
Connsql. open (); // open the database
String strsql = "select count (*) from table name 1"; sqlcommand cmd = new sqlcommand (strsql, connsql); int intnum = (INT) cmd. executescalar (); close (); // close the database
The above is an introduction to the code used for database operations between Asp.net and SQL Server. I hope it will be helpful to you.
Recommended Editing:
1. Implementation of ASP. NET database Driver Class: dbhelper
2. Three-layer design model for ASP. NET Applications
3. Introduction to the role and structure of ngws runtime in ASP. NET