[Visual Basic]
Dim myCMD As SqlCommand = New SqlCommand("SELECT CategoryID, CategoryName FROM Categories;" & _
"SELECT EmployeeID, LastName FROM Employees", nwindConn)
nwindConn.Open()
Dim myReader As SqlDataReader = myCMD.ExecuteReader()
Dim fNextResult As Boolean = True
Do Until Not fNextResult
Console.WriteLine(vbTab & myReader.GetName(0) & vbTab & myReader.GetName(1))
Do While myReader.Read()
Console.WriteLine(vbTab & myReader.GetInt32(0) & vbTab & myReader.GetString(1))
Loop
[Visual Basic]
Dim schemaTable As DataTable = myReader.GetSchemaTable()
Dim myRow As DataRow
Dim myCol As DataColumn
For Each myRow In schemaTable.Rows
For Each myCol In schemaTable.Columns
Console.WriteLine(myCol.ColumnName & " = " & myRow(myCol).ToString())
Next
Console.WriteLine()
Next
OLE DB 章节
分层行集或章节(OLE DB 类型 DBTYPE_HCHAPTER、ADO 类型 adChapter)可使用 OleDbDataReader 来检索。当以 DataReader 的模式前往包括某章节的查询时,该章节将以此 DataReader 中列的模式前往,并公然为 DataReader 对象。
[Visual Basic]
Dim nwindConn As OleDbConnection = New OleDbConnection("Provider=MSDataShape;Data Provider=SQLOLEDB;" & _
"Data Source=localhost;Integrated Security=SSPI;Initial Catalog=northwind")
Dim custCMD As OleDbCommand = New OleDbCommand("SHAPE {SELECT CustomerID, CompanyName FROM Customers} " & _
" APPEND ({SELECT CustomerID, OrderID FROM Orders} AS CustomerOrders " & _
" RELATE CustomerID TO CustomerID)", nwindConn)
nwindConn.Open()
Dim custReader As OleDbDataReader = custCMD.ExecuteReader()
Dim orderReader As OleDbDataReader
Do While custReader.Read()
Console.WriteLine("Orders for " & custReader.GetString(1)) ' custReader.GetString(1) = CompanyName
orderReader = custReader.GetValue(2) ' custReader.GetValue(2) = Orders chapter as DataReader
Do While orderReader.Read()
Console.WriteLine(vbTab & orderReader.GetInt32(1)) ' orderReader.GetInt32(1) = OrderID
Loop
orderReader.Close()
Loop