Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IDataReader question

Status
Not open for further replies.

bigfoot

Programmer
Joined
May 4, 1999
Messages
1,779
Location
US
I just started using the IDataReader object. How do I know without calling .Read if it contains any rows?

Code:
Public Sub ReadMyData(myConnString As String)
    Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders"
    Dim myConnection As New OleDbConnection(myConnString)
    Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
    myConnection.Open()
    Dim myReader As OleDbDataReader
    myReader = myCommand.ExecuteReader()
    ' Always call Read before accessing data.
    While myReader.Read()
        Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
           + myReader.GetString(1))
    End While
    ' always call Close when done reading.
    myReader.Close()
    ' Close the connection when done with it.
    myConnection.Close()
End Sub
 
myreader.hasrows

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
I get an error using myreader.hasrows. It's not a member of System.Data.IDataReader.
 
How are you trying to use the HasRows method?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Like this:

Dim Idr As IDataReader
szSql = "select * from security where sec_username='" & szUserName & "' and sec_password='" & szPassword & "'"

'My database object fills this.
Idr = mDatabaseObject.ExecuteReader(szSql)

If Idr.hasrows Then
'Do something so the user knows.
End If

And I get the funny underline under.

What I want to know up front is are there any records in the IDataReader?
 
Your original code that you posted used a OleDbDataReader:
Code:
Dim myReader As OleDbDataReader [b]' not IDataReader[/b]
Using that example, you could use the HasRows method like you have tried to so in your example where you seem to have changed your code.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Oops. I copied M$'s code just to show.

So it's not interchangable huh?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top