Ado.net Data Operation full contact one (Insert,update,delete)

Source: Internet
Author: User
Tags tostring
ado| data 1.1 Creating a database connection (SQL Server)
1: <%@ Import namespace= "System.Data"%>
2: <%@ Import namespace= "System.Data.SqlClient"%>
3: <%
4:dim MyConnection as SqlConnection
5:myconnection = New SqlConnection ("Server=localhost;database=pubs;uid=sa")
6:
7:myconnection.open ()
8:%>
9:connection opened!
1.2 Creating a database connection (access)
1: <%@ Import namespace= "System.Data"%>
2: <%@ Import namespace= "System.Data.OleDb"%>
3: <%
4:dim MyConnection as OleDbConnection
5:myconnection = New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data
Ccc.gifsource=c:\authors.mdb ")
6:
7:myconnection.open ()
8:%>
9:connection opened!
2.1 Adding records (SQL Server)
9:myconnection.open ()
10:mycommand = New SqlCommand ("Insert testtable (col1) ccc.gifvalues (' Hello ')", MyConnection)
11:mycommand.executenonquery ()
12:myconnection.close ()
:%>
14:new Record inserted!
15:
2.2 Add records (Access)
9:myconnection.open ()
10:mycommand = New OleDbCommand ("Insert into Authors (Author) Values ccc.gif (' Simpson ')", MyConnection)
11:mycommand.executenonquery ()
12:myconnection.close ()
:%>
14:new Record inserted!
15:
3.1 Update data (SQL Server)
9:myconnection.open ()
10:mycommand = New SqlCommand ("UPDATE Authors SET lastname= ' Smith ' ccc.gifwhere lastname= ' Bennett '", MyConnection)
11:mycommand.executenonquery ()
12:myconnection.close ()
:%>
14:record updated!
15:
3.2 Update data (Access)
1: <%@ Import namespace= "System.Data"%>
9:myconnection.open ()
10:mycommand = New OleDbCommand ("UPDATE Authors SET author= ' Bennett ' ccc.gifwhere Author = ' Simpson '", MyConnection)
11:mycommand.executenonquery ()
12:myconnection.close
:%>
14:record updated!15:
3.3 Number of records affected in the update data



9:myconnection = New SqlConnection ("Server=localhost;uid=sa;database=pubs")
10:myconnection.open ()
11:mycommand = New SqlCommand ("UPDATE testtable SET col1= ' Hello ' ccc.gifwhere col1= ' Fred '", MyConnection)
12:recordsaffected = Mycommand.executenonquery ()
13:response.write ("The UPDATE statement modified" & Ccc.gifrecordsAffected.toString () & "records!")
14:myconnection.close
:%>
16:
4.1 Delete data (SQL Server)
1: <%@ Import namespace= "System.Data"%>







9:myconnection.open ()
10:mycommand = New SqlCommand ("DELETE testtable WHERE col1= ' Fred '", MyConnection)
11:mycommand.executenonquery ()
12:myconnection.close ()
:%>
14:record deleted!
15:
4.2 Delete data (access)








9:myconnection.open ()
10:mycommand = New OleDbCommand ("DELETE from Authors ccc.gifwhere Author = ' Simpson '", MyConnection)
11:mycommand.executenonquery ()
12:myconnection.close ()
:%>
14:record deleted!
15:
16:
4.3 Delete the number of records affected in the record

9:myconnection = New SqlConnection ("Server=localhost;uid=sa;database=pubs")
10:myconnection.open ()
11:mycommand = New SqlCommand ("DELETE Authors2 ccc.gifwhere lastname= ' Smith '", MyConnection)
12:recordsaffected = Mycommand.executenonquery ()
13:response.write ("The DELETE statement modified" ccc.gif& recordsaffected.tostring () & "records!")
14:myconnection.close
:%>
16:


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.