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

ado|数据

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
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 ) 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 ccc.gifSource=c:authors.mdb" ) 
9: myConnection.Open()
10: myCommand = New OleDbCommand( "Insert INTO Authors ( Author ) Values 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' 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 ccc.gifSource=c:\authors.mdb" ) 
9: myConnection.Open()
10: myCommand = New OleDbCommand( "UPDATE Authors SET Author='Bennett' 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' ccc.gifWHERE col1='fred'", myConnection )12: recordsAffected = myCommand.ExecuteNonQuery()13: Response.Write( "The UPDATE statement modified " & ccc.gifrecordsAffected.toString() & " records!" )14: myConnection.Close15: %>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 ccc.gifSource=c:\authors.mdb" ) 9: myConnection.Open()10: myCommand = New OleDbCommand( "DELETE FROM Authors 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 ccc.gifWHERE LastName='Smith'", myConnection )
12: recordsAffected = myCommand.ExecuteNonQuery()
13: Response.Write( "The DELETE statement modified " ccc.gif& recordsAffected.toString() & " records!" )
14: myConnection.Close
15: %>
16:

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索sqlserver
, 数据
, access
, connection
, 更新
record
,以便于您获取更多的相关知识。

时间: 2025-01-02 00:18:14

ado.net数据操作全接触一(insert,update,delete)的相关文章

ado.net数据操作全接触三(存储过程,datasets)

ado|存储过程|数据 6.1使用存储过程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 FirstName As String = &

ado.net数据操作全接触二(query,Parameters)

ado|数据 5.1使用SQLDataReader进行数据库查询1: <%@ Import Namespace="System.Data" %>2: <%@ Import NameSpace="System.Data.SqlClient" %>3:4: <%5: Dim myConnection As SqlConnection6: Dim myCommand As SqlCommand7: Dim myDataReader As Sq

ado.net数据操作全接触四(表关联,DataAdapter)

ado|数据 8.1创建一个(主/祥)表关联1: <%@ Import Namespace="System.Data" %>2: <%@ Import NameSpace="System.Data.SqlClient" %>3:4: <%5: Dim myConnection As SqlConnection6: Dim myDataAdapter As SqlDataAdapter7: Dim myDataSet As DataSet

LINQ体验(9)——LINQ to SQL语句之Insert/Update/Delete操作

我们继续讲解LINQ to SQL语句,这篇我们来讨论Insert/Update/Delete操作 .这个在我们的程序中最为常用了.我们直接看例子. Insert/Update/Delete操作插入(Insert)1.简单形式 说明:new一个 对象,使用InsertOnSubmit方法将其加入到对应的集合中,使用SubmitChanges ()提交到数据库. NorthwindDataContext db = new NorthwindDataContext(); var newCustome

简述SQL SERVER触发器内INSERT,UPDATE,DELETE的三种状态

一个触发器内三种INSERT,UPDATE,DELETE状态 CREATE   TRIGGER   tr_T_A   ON     T_A   for   INSERT,UPDATE,DELETE        如IF   exists   (select   *   from   inserted)   and   not   exists   (select   *   from   deleted)   则为   INSERT  如IF   exists(select   *   from

SQL Server触发器insert update delete示例

·只有inserted表有数据时,当前操作为insert: ·inserted和deleted两张表都有数据时,当前操作为update: ·只有deleted表有数据时,当前操作为delete. 创建触发器用 CREATE TRIGGER  代码如下 复制代码 CREATE TRIGGER 触发器名称 ON 表名 FOR INSERT.UPDATE 或 DELETE AS nserted.deleted 这是两个虚拟表,inserted 保存的是 insert 或 update 之后所影响的记录

asp access insert update delete 使用

本教程是一篇asp入门篇的初级教程了,主要是讲asp access insert update delete 简单的使用哦,好了下面我们把它们写在一个函数里面然后再举例说明. Function add_del_update(tablename,str,id) Select Case str  Case "insert":    sql="select * from ["&tablename&"] where id=null"   

MySQL 4.1.0 中文参考手册 --- 6.4 数据操纵:SELECT, INSERT, UPDATE, DELETE

mysql|select|参考|参考手册|数据|中文 MySQL 4.1.0 中文参考手册 --- 犬犬(心帆)翻译 MySQL Reference Manual for version 4.1.0-alpha. 6.4 数据操纵:SELECT, INSERT, UPDATE, DELETE6.4.1 SELECT 句法 SELECT [STRAIGHT_JOIN] [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT] [SQL_CACH

Merge(在一条语句中使用Insert,Update,Delete) 对两个表进行同步数据

SQL Server 2008提供了一个增强的SQL命令Merge,用法参看MSDN:http://msdn.microsoft.com/zh-cn/library/bb510625.aspx 功能:根据与源表联接的结果,对目标表执行插入.更新或删除操作.例如,根据在另一个表中找到的差异在一个表中插入.更新或删除行,可以对两个表进行同步. 我们看一个例子,假如,有一总产品列表,一个分店产品列表,需要从分店添加产品时更新总产品列表. 总产品表,分店产品表结构完全一致: if OBJECT_ID('