这些都是网上搜索到的,我把他放在自己的博客里,作为笔记
1.1创建数据库连接(sqlserver)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.SqlClient" %> <% Dim myConnection As SqlConnection myConnection = New SqlConnection( "server=localhost;database=Pubs;uid=sa" ) myConnection.Open() %> Connection Opened!
1.2创建数据库连接(access)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.OleDb" %> <% Dim myConnection As OleDbConnection myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:authors.mdb" ) myConnection.Open() %> Connection Opened!
2.1添加纪录(sqlserver)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.SqlClient" %> <% Dim myConnection As SqlConnection Dim myCommand As SqlCommand myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" ) myConnection.Open() myCommand = New SqlCommand( "Insert testTable ( col1 ) http://aspfree.com/chapters/sams/graphics/ccc.gifValues ( 'Hello' )", myConnection ) myCommand.ExecuteNonQuery() myConnection.Close() %> New Record Inserted!
2.2添加纪录(access)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.OleDb" %> <% Dim myConnection As OleDbConnection Dim myCommand As OleDbCommand myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:authors.mdb" ) myConnection.Open() myCommand = New OleDbCommand( "Insert INTO Authors ( Author ) Values http://aspfree.com/chapters/sams/graphics/ccc.gif( 'Simpson' )", myConnection ) myCommand.ExecuteNonQuery() myConnection.Close() %> New Record Inserted!
3.1更新数据(sqlserver)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.SqlClient" %> <% Dim myConnection As SqlConnection Dim myCommand As SqlCommand myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" ) myConnection.Open() myCommand = New SqlCommand( "UPDATE Authors SET LastName='Smith' http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE LastName='Bennett'", myConnection ) myCommand.ExecuteNonQuery() myConnection.Close() %> Record Updated!
3.2更新数据(access)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.OleDb" %> <% Dim myConnection As OleDbConnection Dim myCommand As OleDbCommand myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:authors.mdb" ) myConnection.Open() myCommand = New OleDbCommand( "UPDATE Authors SET Author='Bennett' http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE Author = 'Simpson'", myConnection ) myCommand.ExecuteNonQuery() myConnection.Close %> Record Updated!
3.3更新数据中受影响的记录数
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.SqlClient" %> <% Dim myConnection As SqlConnection Dim myCommand As SqlCommand Dim recordsAffected As Integer myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" ) myConnection.Open() myCommand = New SqlCommand( "UPDATE testTable SET col1='hello' http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE col1='fred'", myConnection ) recordsAffected = myCommand.ExecuteNonQuery() Response.Write( "The UPDATE statement modified " & http://aspfree.com/chapters/sams/graphics/ccc.gifrecordsAffected.toString() & " records!" ) myConnection.Close %>
4.1删除数据(sqlserver)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.SqlClient" %> <% Dim myConnection As SqlConnection Dim myCommand As SqlCommand myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" ) myConnection.Open() myCommand = New SqlCommand( "DELETE testTable WHERE col1='fred'", myConnection ) myCommand.ExecuteNonQuery() myConnection.Close() %> Record Deleted!
4.2删除数据(access)
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.OleDb" %> <% Dim myConnection As OleDbConnection Dim myCommand As OleDbCommand myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:authors.mdb" ) myConnection.Open() myCommand = New OleDbCommand( "DELETE FROM Authors http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE Author = 'Simpson'", myConnection ) myCommand.ExecuteNonQuery() myConnection.Close() %> Record Deleted!
4.3删除纪录中受影响的记录数
<%@ Import Namespace="System.Data" %> <%@ Import NameSpace="System.Data.SqlClient" %> <% Dim myConnection As SQLConnection Dim myCommand As SQLCommand Dim recordsAffected As Integer myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" ) myConnection.Open() myCommand = New SqlCommand( "DELETE Authors2 http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE LastName='Smith'", myConnection ) recordsAffected = myCommand.ExecuteNonQuery() Response.Write( "The DELETE statement modified " http://aspfree.com/chapters/sams/graphics/ccc.gif& recordsAffected.toString() & " records!" ) myConnection.Close %>