Objective: to add or delete a modification record
In the past, we used to add or DELETE records in ASP, add EXECUTE () to SQL statements, or directly use the NEW, DELETE, UPDATE, and other methods of RECORDSET to add or DELETE modification records. In ASP. NET, we use SQL statements and COMMAND objects to execute SQL statements to add and delete modification records. This is easier than reading records. In fact, there is only one difference. Just change ExecuteReader () to ExecuteNonQuery (), because we don't need to return values.
String strConnection = "Provider = Microsoft. Jet. OleDb.4.0; Data Source = ";
StrConnection + = Server. MapPath (strDb );
OleDbConnection objConnection = new OleDbConnection (strConnection );
OleDbCommand objCommand = new OleDbCommand ("here is the SQL statement", objConnection );
ObjConnection. Open ();
OleDbDataReader objDataReader = objCommand. ExecuteNonQuery ();
-----------------------
Dim objConnection as OleDbConnection
Dim objCommand as OleDbCommand
ObjConnection = new OleDbConnection (Provider = Microsoft. Jet. OleDb.4.0; Data Source = "+ Server. MapPath (strDb ))
ObjCommand = new OleDbCommand ("here is the SQL statement", objConnection)
ObjConnection. Open ()
ObjDataReader = objCommand. ExecuteNoQuery ()
The following example illustrates the SQL statement (ACCESS ):
Add record: insert int
O table name (Field 1, Field 2) values (string 1, string 2) where Condition
Delete record: delete from table name where Condition
Modify record: update table name set field 1 = ××, Field 2 = ×× where Condition
Note that if the SQL Server deletion record is the delete table name, you do not need to add the from statement.
Let's talk about this today. Tomorrow we will talk about the most famous DATAGRID in ASP. NET.