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 useSQL statementAddCommand objectTo execute SQL statements to add or delete modification records. This is easier than reading records. There is actually only one difference,Change executereader () to executenonquery ().Because we do not need to return values.
// Obtain the form input
String usersite = "";
String userface = "";
Usersite = request. Form. Get ("usersite"). tostring (). Trim ();
Userface = request. Form. Get ("userface"). tostring (). Trim ();
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 ();
Objcommand. executenonquery (); // Note: Write this command directly here.
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 into 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 clause.