COunt records/rows returned.

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I use the following to populate a listbox (exert) :

sql = "Select CONTACT_ID, CONTACT_NAME from tblContact WHERE CONTACT_DELETE
<> 1 AND CONTACT_NAME LIKE " & "'%" & Me.txtSearchName.Text & "%'" & " order
by CONTACT_NAME"
' Me.Label1.Text = sql
Dim conn As New OdbcConnection(strConn)
Dim Cmd As New OdbcCommand(sql, conn)
Dim objDR As OdbcDataReader
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
emplist.DataSource = objDR
emplist.DataValueField = "CONTACT_ID"
emplist.DataTextField = "CONTACT_NAME"
emplist.DataBind()

Can someone tell me how I would detect if there where no records returned ?

Thanks in Advance
 
In VS 2003, the DataReader has a Property .HasRows...boolean so if
dr.HasRows then you got something.

In 2002, you'll need to iterate through it and get a count manually which
doesn't look like it fits well with what you are doing. Hopefully you have
2003. But if you don't, it'll only be a few more lines.

HTH,

Bill
 
Armin:

You are going to have to iterate then. While (dr.Read and myBool)

'then in the first pass, set myBool to false, if it executes at all then you
have rows...
Paul said:
As william said.

I dont have 2003.
 
William Ryan said:
Armin:

You are going to have to iterate then. While (dr.Read and myBool)

'then in the first pass, set myBool to false, if it executes at all
then you have rows...


I didn't know this here - I'd only have known in the ADO.NET group. ;-)
 
Back
Top