...

View Full Version : Help with DataReader class in VB.Net



Bob Burns
08-17-2004, 05:59 PM
Hi,
I create a datareader object but I would like to be able to iterate through the elements using a for statement. Doing something as follows
data_reader = command.ExecuteReader()

Row_Array1 = data_reader.GetRowArray()
Row_Array2 = data_reader.GetRowArray()

For Row_Array1(0) To Row_Array.GetUpperBoundValue()
For Row_Array2(1) To Row_Array.GetUpperBoundValue()

if Row_Array1(0).GetString().Equals(Row_Array2(1).GetString()) Then

//do something
End If
Next //inner for
Next //outer for

Thanks
Bob

gtsikes
08-25-2004, 12:31 AM
I do not see a DataReader method called GetRowArray() so I will prodeed with 2 seperate DataReader objects.



Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Documents an"& _
"d Settings\sikesj01\My Documents\Schedule\schedule.mdb"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
Dim queryString1 As String = "SELECT [EMP].[EMPNUM], [EMP].[EMPNAME] FROM [EMP]"
Dim queryString2 As String = "SELECT [EMPSHIFT].[EMPNUM], [EMPSHIFT].[SHIFT_DATE] FROM [EMPSHIFT]"

Dim dbCommand1 As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand1.CommandText = queryString1
dbCommand1.Connection = dbConnection

Dim dbCommand2 As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand2.CommandText = queryString2
dbCommand2.Connection = dbConnection


dbConnection.Open
Dim dataReader1 As System.Data.IDataReader = dbCommand1.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Dim dataReader2 As System.Data.IDataReader = dbCommand2.ExecuteReader(System.Data.CommandBehavior.CloseConnection)


While dataReader2.Read
While dataReader1.Read
If dataReader2.GetString("EMPNUM") = datareader1.GetString("EMPNUM") then
'then do something
End if
End While
End While



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum