ado.net数据操作全接触一(insert,update,delete)

原创 2005年03月02日 10:49:00
1.1创建数据库连接(sqlserver)
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创建数据库连接(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
http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:/authors.mdb" )
6:
7: myConnection.Open()
8: %>
9: Connection Opened!
2.1添加纪录(sqlserver)

1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.SqlClient" %>
3:
4: <%
5: Dim myConnection As SqlConnection
6: Dim myCommand As SqlCommand
7:
8: myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" )
9: myConnection.Open()
10: myCommand = New SqlCommand( "Insert testTable ( col1 ) http://aspfree.com/chapters/sams/graphics/ccc.gifValues ( 'Hello' )", myConnection )
11: myCommand.ExecuteNonQuery()
12: myConnection.Close()
13: %>
14: New Record Inserted!
15:
2.2添加纪录(access)
1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.OleDb" %>
3:
4: <%
5: Dim myConnection As OleDbConnection
6: Dim myCommand As OleDbCommand
7:
8: myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:authors.mdb" )
9: myConnection.Open()
10: myCommand = New OleDbCommand( "Insert INTO Authors ( Author ) Values http://aspfree.com/chapters/sams/graphics/ccc.gif( 'Simpson' )", myConnection )
11: myCommand.ExecuteNonQuery()
12: myConnection.Close()
13: %>
14: New Record Inserted!
15:
3.1更新数据(sqlserver)
1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.SqlClient" %>
3:
4: <%
5: Dim myConnection As SqlConnection
6: Dim myCommand As SqlCommand
7:
8: myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" )
9: myConnection.Open()
10: myCommand = New SqlCommand( "UPDATE Authors SET LastName='Smith' http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE LastName='Bennett'", myConnection )
11: myCommand.ExecuteNonQuery()
12: myConnection.Close()
13: %>
14: Record Updated!
15:
3.2更新数据(access)
1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.OleDb" %>
3:
4: <%
5: Dim myConnection As OleDbConnection
6: Dim myCommand As OleDbCommand
7:
8: myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:/authors.mdb" )
9: myConnection.Open()
10: myCommand = New OleDbCommand( "UPDATE Authors SET Author='Bennett' http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE Author = 'Simpson'", myConnection )
11: myCommand.ExecuteNonQuery()
12: myConnection.Close
13: %>
14: Record Updated!15:
3.3更新数据中受影响的记录数
1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.SqlClient" %>
3:
4: <%
5: Dim myConnection As SqlConnection
6: Dim myCommand As SqlCommand
7: Dim recordsAffected As Integer
8:
9: myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" )
10: myConnection.Open()
11: myCommand = New SqlCommand( "UPDATE testTable SET col1='hello' http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE col1='fred'", myConnection )
12: recordsAffected = myCommand.ExecuteNonQuery()
13: Response.Write( "The UPDATE statement modified " & http://aspfree.com/chapters/sams/graphics/ccc.gifrecordsAffected.toString() & " records!" )
14: myConnection.Close
15: %>
16:
4.1删除数据(sqlserver)
1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.SqlClient" %>
3:
4: <%
5: Dim myConnection As SqlConnection
6: Dim myCommand As SqlCommand
7:
8: myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" )
9: myConnection.Open()
10: myCommand = New SqlCommand( "DELETE testTable WHERE col1='fred'", myConnection )
11: myCommand.ExecuteNonQuery()
12: myConnection.Close()
13: %>
14: Record Deleted!
15:
4.2删除数据(access) 1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.OleDb" %>
3:
4: <%
5: Dim myConnection As OleDbConnection
6: Dim myCommand As OleDbCommand
7:
8: myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:/authors.mdb" )
9: myConnection.Open()
10: myCommand = New OleDbCommand( "DELETE FROM Authors http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE Author = 'Simpson'", myConnection )
11: myCommand.ExecuteNonQuery()
12: myConnection.Close()
13: %>
14: Record Deleted!
15:
16:4.3删除纪录中受影响的记录数1: <%@ Import Namespace="System.Data" %>
2: <%@ Import NameSpace="System.Data.SqlClient" %> 3: 4: <% 5: Dim myConnection As SQLConnection 6: Dim myCommand As SQLCommand 7: Dim recordsAffected As Integer 8: 9: myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" )10: myConnection.Open()11: myCommand = New SqlCommand( "DELETE Authors2 http://aspfree.com/chapters/sams/graphics/ccc.gifWHERE LastName='Smith'", myConnection )12: recordsAffected = myCommand.ExecuteNonQuery()13: Response.Write( "The DELETE statement modified " http://aspfree.com/chapters/sams/graphics/ccc.gif& recordsAffected.toString() & " records!" )14: myConnection.Close15: %>16:

ado.net数据操作全接触一(insert,update,delete)

  • zgqtxwd
  • zgqtxwd
  • 2008年05月01日 03:28
  • 62

ado.net数据操作全接触一(insert,update,delete

1.1创建数据库连接(sqlserver)1: 2: 3: 4: Dim myConnection As SqlConnection5: myConnection = New SqlConnectio...
  • redrainy
  • redrainy
  • 2007年02月25日 14:27
  • 375

掌握SQL四条最基本的数据操作语句:Insert,Select,Update和Delete

掌握SQL四条最基本的数据操作语句:Insert,Select,Update和Delete。
  • newnewman80
  • newnewman80
  • 2010年12月30日 11:59
  • 1256

SQL中delete+insert 和update哪个快

首先说,顺序是insert为1,其次delete再者update因为delete和update要涉及到全表扫描, update是最慢的,如果数据很多的时候最好使用delete+insert,而非upd...
  • TiramisuH
  • TiramisuH
  • 2009年10月16日 13:08
  • 4680

oracle更新(insert delete update truncate)

oracle更新(insert delete update) ①insert create table people(        id number primary key,   ...
  • kevin_love_it
  • kevin_love_it
  • 2017年09月17日 13:05
  • 246

创建INSERT、DELETE、UPDATE 触发器示例 .

触发器是基于一个表创建的,但是可以针对多个表进行操作。所以触发器可以用来对表实施复杂的完整性的约束,当触发器所保存的数据发生改变时,触发器所保存的数据发生改变时,触发器被自动激活,从而防止对数据的不正...
  • u010078133
  • u010078133
  • 2015年03月13日 11:10
  • 2131

单个触发器判断Insert/Delete/Update操

问题已解决,分享之: 插入操作(Insert):Inserted表有数据,Deleted表无数据 删除操作(Delete):Inserted表无数据,Deleted表有数据 更新操作(Updat...
  • tianwailaibin
  • tianwailaibin
  • 2012年10月25日 15:35
  • 1236

[C#] 数据库操作 - Insert, Read, Delete, Update

public DataTable ReadDB(string SqlCmdString) { DataTable dt = new DataTable(); ...
  • shylx123
  • shylx123
  • 2013年07月22日 22:19
  • 1885

数据库的insert , delete , update , select 的基本语句

1.Insert  语法: INSERT INTO 表名称 VALUES (值1, 值2,....) 我们也可以指定所要插入数据的列: INSERT INTO table_name...
  • mini_jike
  • mini_jike
  • 2015年05月10日 01:36
  • 859

SQL SERVER INSERT、UPDATE 、DELETE、SELECT增、改、删、查

1、insert插入一条记录: 2、insert插入多条记录: 3、update指定条件更新记录: 4、delete指定条件删除记录:delete * from person where id=...
  • baidu_32731497
  • baidu_32731497
  • 2016年05月19日 22:50
  • 1929
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ado.net数据操作全接触一(insert,update,delete)
举报原因:
原因补充:

(最多只允许输入30个字)