Vb教程 Vb.net教程 Vfp教程 C/C++教程 Vc/Vc++教程 Delphi教程 Java教程 Powerbuilder
  杀毒频道 | 短信频道 | 网络电视 | 论文中心 | 学上网 | 学软件 | 网页特效 | 电脑基础 | 论坛  
  NCRE | 软考 | CET | 职称英语 | 司法考试 | 报关员 | 公务员 | CATTI | CPA考试  
  Html教程 | Css教程 | Xml教程 | Asp教程 | Asp.net | Php教程 | Jsp教程 | Linux教程 | QQ技巧  
Photoshop Illustrator ImageReady Maya教程 3D Max教程 Lightscape Coredraw教程 Authorware Autocad教程 Freehand教程
Access教程 Mysql教程 Sql server Oracle教程 Word教程 Excel教程 Powerpoint Frontpage Asp.net源码 Php源代码
Flash教程 Fireworks Dreamweaver C#教程 outlook教程 系统安装 vbscript教程 Javascript Jsp源代码 Asp源代码
您的位置:首页 >> Vb.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.Close

15: %>

[返回]

编程语言 web开发 数据库 网络技术 操作系统 服务器 网页设计 图形设计 办公软件 常用软件 学电脑

Copyright© www.bianceng.cn Powered by 编程入门网 All Rights Reserved.
关于本站 | 版权声明 | 联系我们 | 友情链接 |
编程入门网 版权所有