Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with DataReader class in VB.Net

    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

  • #2
    New Coder
    Join Date
    Jul 2003
    Location
    Jacksonville, FL
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    DataReader Read method

    I do not see a DataReader method called GetRowArray() so I will prodeed with 2 seperate DataReader objects.

    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •