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

原创 2005年03月02日 10:50:00
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:

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

5.1使用SQLDataReader进行数据库查询1: 2: 3:4: 5: Dim myConnection As SqlConnection6: Dim myCommand As SqlComma...
  • redrainy
  • redrainy
  • 2007年02月25日 14:25
  • 391

ado.net数据操作全接触

ado.net数据操作全接触一(insert,update,delete)window.attachEvent("onload",function (){AutoSizeDIV(CODE_4439)}...
  • deepbluekk
  • deepbluekk
  • 2006年03月14日 23:59
  • 491

Hiberante中No positional parameters in query: (找不到查询位置)

在hibernate的应用查询时会抛出java.lang.IllegalArgumentException: No positional parameters in query: 这个异常的意思...
  • yali1990515
  • yali1990515
  • 2012年06月10日 19:12
  • 16401

hibernate : No positional parameters in query 错误解决办法

项目中一个查询的语句发生错误,错误提示如下: java.lang.IllegalArgumentException: No positional parameters in query: from ...
  • hb_peng
  • hb_peng
  • 2015年07月03日 11:35
  • 3948

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

6.1使用存储过程1: 2: 3:4: 5: Dim myConnection As SqlConnection6: Dim myCommand As SqlCommand7: Dim FirstNa...
  • redrainy
  • redrainy
  • 2007年02月25日 14:24
  • 432

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

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

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

  • zgqtxwd
  • zgqtxwd
  • 2008年05月01日 04:25
  • 244

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

java URL追加query parameters

public class URITest { public static URI appendUri(String uri, String appendQuery) throws URISyn...
  • bin622
  • bin622
  • 2017年06月05日 14:37
  • 364

黑马程序员之ADO.NET学习笔记:SqlParameter(Sql参数)

1. 几个重要的属性          ParameterName:设置参数名      Value:给参数设置值      Size:设置参数字节最大大小(以字节为单位)      SqlDbTyp...
  • xutingzhou
  • xutingzhou
  • 2012年09月07日 10:04
  • 929
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:ado.net数据操作全接触二(query,Parameters)
举报原因:
原因补充:

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