1. sqlcommand. executenonquery () This method is mainly used to execute SQL statement insert, modify, and delete commands, and return the affected number of rows without returning data from the Operation database.
2. sqlcommand. executereader () This method is mainly used to execute the SELECT statement of SQL. The executereader () method mainly provides the method to read data in the database sequentially, and then returns the sqlreader object, the editor can use the read method to read the content of each field in each record cyclically. To create a sqldatareader, you must call the executereader () method of the sqlcommand object to return data from the data table in the database:
Sqlconnection conn = new sqlconnection ("");
String sqlcmd = "select * from table name ";
Sqlcommand cmd = new sqlcommand (sqlcmd, Conn );
Conn. open ();
Sqldatareader DR = cmd. executereader ();
If (dr. Read () = true)
{
Listbox1.items. Add (string. Format ("[{0}], \" {1} \ "", Dr [0], Dr [1]);
}
Conn. Close ();
3. sqlcommand. excutescaler () is used to return a value. For example, the count () function is used to calculate the number of all records in the table, or sum () is used to calculate the sum of the Data functions. Sqlcommand. commandtext is used to obtain or set to execute T--SQL statements, table names, and stored procedures.
# Region uses sqlcommand. excutescaler () to return the number of rows of data
Sqlconnection conn = new sqlconnection ("");
Sqlcommand cmd = new sqlcommand ();
Cmd. Connection = conn;
Conn. open ();
Cmd. commandtext = "select count (*) from table name ";
Int num = (INT) cmd. executescalar ();
Response. Write (string. Format ("{0}", num ));
# Endregion