1. Basic Steps for ASP. NET database operations:
Common Methods for ASP. NET data operations:
A. ExecuteReader ()
The returned result is a SqlDataReader object or OleDbDataReader object. Each return or operation guides a record to be stored in the server's memory.
Compared with DataSet, quick access is usually used for query operations.
B. ExecuteNonQuery ()
C. ExecuteScalar () returns the Object type. If SELECT is executed, the returned result is the first column in the first row after the query.
Returns the number of rows affected by the database, which is the first choice for database transaction processing.
Public int test ()
{
String connStr = @ "server = Miro; database = newssystem; uid = sa; pwd = sa ";
SqlConnection conn = new SqlConnection (connStr );
Conn. Open ();
String SQL = "insert into category (name) values ('ttt ')";
SqlCommand cmd = new SqlCommand (SQL, conn );
Int res = cmd. ExecuteNonQuery ();
Conn. Close ();
Return res;
}
Public DataTable test (string SQL)
{
DataTable dt = new DataTable ();
String connStr = @ "server = Miro; database = newssystem; uid = sa; pwd = sa ";
SqlConnection conn = new SqlConnection (connStr );
Conn. Open ();
SqlCommand cmd = new SqlCommand (SQL, conn );
SqlDataReader sdr = cmd. ExecuteReader ();
Dt. Load (sdr );
Sdr. Close ();
Conn. Close ();
Return dt;
}
2. Tips for:
You can add the tool --> Custom --> command --> debugging to the toolbar without debugging.