网站导航免费论文 原创论文 论文搜索 原创论文 网学软件 学术大家 资料中心 会员中心 问题解答 原创论文 大学论文导航 设计下载 最新论文 下载排行 原创论文 论文源代码
返回网学首页
网学联系
最新论文 推荐专题 热门论文 素材专题
当前位置: 网学 > 编程文档 > ASP.net > 正文

ado.net数据操作全接触

来源:http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 14/02/27

【编者按】网学网ASP.net频道为大家收集整理了“ado.net数据操作全接触“提供大家参考,希望对大家有所帮助!


  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详细研究(1)
  • 下一篇资讯: ADO.NET对象的构造
  • 网学推荐

    免费论文

    原创论文

    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号