自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

進(jìn)行檢索ADO.NET 數(shù)據(jù)說明

開發(fā) 后端
設(shè)置 ADO.NET 數(shù)據(jù)屬性。這樣,就可以讀取 Errors 集合的 Count 屬性以測試返回的警告,對C#我沒有把握。它可能可以訪問C/C++類庫。

以下代碼列表演示如何使用 ADO.NET 數(shù)據(jù)提供程序從數(shù)據(jù)庫中檢索數(shù)據(jù)。數(shù)據(jù)在一個 DataReader 中返回。有關(guān)更多信息,請參見使用 DataReader 檢索數(shù)據(jù) (ADO.NET)。

SqlClient
此示例中的代碼假定您可以連接到 Microsoft SQL Server 7.0 或更高版本上的 Northwind 示例數(shù)據(jù)庫。ADO.NET 數(shù)據(jù)在此情形 5 中,示例代碼創(chuàng)建一個 SqlCommand 以從 Products 表中選擇行,并添加 SqlParameter 來將結(jié)果限制為其 UnitPrice 大于指定參數(shù)值的行。

SqlConnection 在 using 塊內(nèi)打開,這將確保在代碼退出時會關(guān)閉和釋放資源。示例代碼使用 SqlDataReader 執(zhí)行命令,ADO.NET 數(shù)據(jù)并在控制臺窗口中顯示結(jié)果。此示例中的代碼假定您可以連接到 Microsoft Access Northwind 示例數(shù)據(jù)庫。#t#

在此情形 5 中,示例代碼創(chuàng)建一個ADO.NET 數(shù)據(jù) OleDbCommand 以從 Products 表中選擇行,并添加 OleDbParameter 來將結(jié)果限制為其 UnitPrice 大于指定參數(shù)值的行。OleDbConnection 在 using 塊內(nèi)打開,這將確保在代碼退出時會關(guān)閉和釋放資源。示例代碼使用 OleDbDataReader 執(zhí)行命令,并在控制臺窗口中顯示結(jié)果。

  1. Option Explicit On  
  2. Option Strict On  
  3.  
  4. Imports System  
  5. Imports System.Data  
  6. Imports System.Data.SqlClient  
  7.  
  8. Public Class Program  
  9. Public Shared Sub Main()  
  10.  
  11. Dim connectionString As String = GetConnectionString()  
  12. Dim queryString As String = _ 
  13.  "SELECT CategoryID, CategoryName FROM dbo.Categories;"  
  14.  
  15. Using connection As New SqlConnection(connectionString)  
  16. Dim command As SqlCommand = connection.CreateCommand()  
  17. command.CommandText = queryString 
  18. Try  
  19. connection.Open()  
  20. Dim dataReader As SqlDataReader = _ 
  21.  command.ExecuteReader()  
  22. Do While dataReader.Read()  
  23. Console.WriteLine(vbTab & "{0}" & vbTab & "{1}", _  
  24.  dataReader(0), dataReader(1))  
  25. Loop  
  26. dataReader.Close()  
  27.  
  28. Catch ex As Exception  
  29. Console.WriteLine(ex.Message)  
  30. End Try  
  31. End Using  
  32. End Sub  
  33.  
  34. Private Shared Function GetConnectionString() As String  
  35. ' To avoid storing the connection string in your code,  
  36. ' you can retrieve it from a configuration file.  
  37. Return "Data Source=(local);Initial Catalog=Northwind;" _  
  38.  & "Integrated Security=SSPI;"  
  39. End Function  
  40. End Class 
責(zé)任編輯:chenqingxiang 來源: 計(jì)世網(wǎng)
相關(guān)推薦

2009-12-31 10:57:14

ADO.NET SEL

2009-12-22 09:43:20

ADO.NET對象

2009-12-18 17:01:21

ADO.NET數(shù)據(jù)

2010-01-04 15:27:31

ADO.NET SQL

2009-12-29 15:44:11

ADO.NET檢索技術(shù)

2009-12-25 09:25:54

ADO.NET實(shí)例

2009-12-31 15:55:06

ADO.NET結(jié)構(gòu)

2010-01-04 09:43:51

ADO.NET對象模型

2009-12-29 13:57:30

訪問ADO.NET

2009-12-30 15:11:35

ADO.NET數(shù)據(jù)

2009-11-13 10:31:07

ADO.NET Dat

2009-12-31 10:16:45

ADO.NET體系結(jié)構(gòu)

2010-01-04 10:39:33

ADO.NET描述

2009-12-29 15:22:40

ADO.NET類庫

2009-12-21 17:29:43

ADO.NET模型

2009-12-24 09:34:47

調(diào)用ADO.NET

2009-12-22 17:43:26

ADO.Net技術(shù)

2009-12-30 16:05:20

ADO.NET實(shí)例

2009-12-22 11:17:58

ADO.NET產(chǎn)品

2009-12-21 10:37:05

Ado.Net 實(shí)例
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號