net数据库操作www.weide1946.com

2019-10-01 02:47 来源:未知

这一个都以网络寻觅到的,作者把他献身自个儿的博客里,作为笔记

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创建数据库连接

<%@ Import Namespace="System.Data" %><%@ Import NameSpace="System.Data.OleDb" %> <% Dim myConnection As OleDbConnection myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATAhttp://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  http://aspfree.com/chapters/sams/graphics/ccc.gifValues ( 'Hello' )", myConnection ) myCommand.ExecuteNonQuery() myConnection.Close() %>New Record Inserted!

2.2添加纪录

<%@ 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  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更新数据

<%@ 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删除数据

 <%@ 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 %>
版权声明:本文由韦德娱乐1946_韦德娱乐1946网页版|韦德国际1946官网发布于网络编程,转载请注明出处:net数据库操作www.weide1946.com