The seventh day of ASP.net

Source: Internet
Author: User

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.

Related Article

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.