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: