Add, delete, and modify records in ASP. NET

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.