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数据操作全接触二(query,Parameters)

文章来源:互联网

5.1使用SQLDataReader进行数据库查询
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 myDataReader As SqlDataReader
8:
9: myConnection = New SqlConnection( "server=localhost;uid=sa;database=Pubs" )
10: myConnection.Open()
11: myCommand = New SqlCommand( "Select * from Authors", myConnection )
12: myDataReader = myCommand.ExecuteReader()
13: While myDataReader.Read()
14:Response.Write( myDataReader.Item( "au_lname" ) )
15: End While
16: myDataReader.Close()
17: myConnection.Close()
18: %>
19:
5.2在C#中使用SqlDataReader 进行数据库查询 1: <%@ Page Language="C#" %>

2: <%@ Import Namespace="System.Data" %>

3: <%@ Import NameSpace="System.Data.SqlClient" %>

4:

5: <%

6: SqlDataReader myDataReader;

7: SqlConnection myConnection = new http://aspfree.com/chapters/sams/graphics/ccc.gifSqlConnection( "server=localhost;uid=sa;database=Pubs" );

8: myConnection.Open();

9: SqlCommand myCommand = new SqlCommand( "Select * from http://aspfree.com/chapters/sams/graphics/ccc.gifAuthors", myConnection );

10: myDataReader = myCommand.ExecuteReader();

11: while ( myDataReader.Read() )

12: {

13:Response.Write( myDataReader[ "au_lname" ].ToString() );

14: }

15: myDataReader.Close();

16: myConnection.Close();

17: %>

18:

5.3使用OleDbDataReader进行数据库查询

1: <%@ Import Namespace="System.Data" %>

2: <%@ Import NameSpace="System.Data.OleDb" %>

3:

4: <%

5: Dim myConnection As OleDbConnection

6: Dim myCommand As OleDbCommand

7: Dim myDataReader As OleDbDataReader

8:

9: myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA http://aspfree.com/chapters/sams/graphics/ccc.gifSource=c:\authors.mdb" )

10: myConnection.Open()

11: myCommand = New OleDbCommand( "Select * from Authors", myConnection )

12: myDataReader = myCommand.ExecuteReader()

13: While myDataReader.Read

14:Response.Write( myDataReader.Item( "author" ) )

15: End While

16: myDataReader.Close()

17: myConnection.Close

18: %>

19:

5.5使用sql Parameters

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 = "Robert"

8: Dim LastName As String = "Johnson"

9:

10: myConnection = New SqlConnection( "server=localhost;uid=sa;pwd=secret;database=myData" )

11: myConnection.Open()

12: myCommand = New SQLCommand( "Insert Authors ( FirstName, LastName ) http://aspfree.com/chapters/sams/graphics/ccc.gifValues ( @FirstName, @LastName )", myConnection )

13:

14: myCommand.Parameters.Add( New SqlParameter( "@FirstName", http://aspfree.com/chapters/sams/graphics/ccc.gifSqlDbType.Varchar, 30 ))

15: myCommand.Parameters( "@FirstName" ).Value = FirstName

16:

17: myCommand.Parameters.Add( New SqlParameter( "@LastName", http://aspfree.com/chapters/sams/graphics/ccc.gifSqlDbType.Varchar, 30 ))

18: myCommand.Parameters( "@LastName" ).Value = LastName

19:

20: myCommand.ExecuteNonQuery()

21: myConnection.Close()

22: %>

23: Record Inserted!

5.6使用sql Parameters(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: Dim FirstName As String = "Robert"

8: Dim LastName As String = "Johnson"

9:

10: myConnection = New OleDbConnection( "PROVIDER=Microsoft.Jet.OLEDB.4.0;http://aspfree.com/chapters/sams/graphics/ccc.gifDATA Source=c:\author2.mdb" )

11: myConnection.Open()

12: myCommand = New OleDbCommand( "Insert INTO Authors ( FirstName, LastName ) http://aspfree.com/chapters/sams/graphics/ccc.gifValues ( @FirstName, @LastName )", myConnection )

13:

14: myCommand.Parameters.Add( New OleDbParameter( "@FirstName", http://aspfree.com/chapters/sams/graphics/ccc.gifOleDbType.Varchar, 30 ))

15: myCommand.Parameters( "@FirstName" ).Value = FirstName

16:

17: myCommand.Parameters.Add( New OleDbParameter( "@LastName", http://aspfree.com/chapters/sams/graphics/ccc.gifOleDbType.Varchar, 30 ))

18: myCommand.Parameters( "@LastName" ).Value = LastName

19:

20: myCommand.ExecuteNonQuery()

21: myConnection.Close()

22: %>

23: Record Inserted!

24:

[返回]

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

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