473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

COunt records/rows returned.

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.Clos eConnection)
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

Nov 20 '05 #1
4 4275
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
"Paul" <pa**@themedialounge.com> wrote in message
news:uu*************@tk2msftngp13.phx.gbl...
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.Clos eConnection)
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

Nov 20 '05 #2
As william said.

I dont have 2003.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u7*************@tk2msftngp13.phx.gbl...
"Paul" <pa**@themedialounge.com> schrieb
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.Clos eConnection)
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 ?


It's not hard to find when having a look at the DataReader's members:
objDR.HasRows
--
Armin

Nov 20 '05 #3
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" <pa**@themedialounge.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
As william said.

I dont have 2003.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u7*************@tk2msftngp13.phx.gbl...
"Paul" <pa**@themedialounge.com> schrieb
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.Clos eConnection)
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 ?


It's not hard to find when having a look at the DataReader's members:
objDR.HasRows
--
Armin


Nov 20 '05 #4
"William Ryan" <do********@comcast.nospam.net> schrieb
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. ;-)
--
Armin

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: leegold2 | last post by:
Below is some code from a FULLTEXT search. My question is how do I get a count of the number of rows found by the search? $query="SELECT * FROM balloon_txt WHERE MATCH(access_no, recs_txt)...
20
by: Guru | last post by:
Hi I have a table which contains number of rows. I want to fetch the last 5 records from the table. I know for the first 'n' records we can use FETCH FIRST n ROWS ONLY command. But i want to...
1
by: James | last post by:
Access 2003, trying to count the number of records that meet a criteria. According to Help: "In the Database window, click Queries under Objects, and then click New on the database window...
6
by: Kulwinder Sayal | last post by:
Hi In ASP it was so simple to get the no. of records using RecordCount. Can anyone help me how to write the no. of records my sqlquery has searched Thanks Kulwinder
7
by: Agnes | last post by:
In my store procedure , i will select * from myTable, and I will while-loop the result by using datareader in vb.net . Now, Can I know the number of records before I while-loop the resut ??
10
by: Zak McGregor | last post by:
Hi all is it possible to get a count(1) statemment, for example here: select count(1) from results where fixture=4916 and winner=away group by winner; to return a 0 value instead of...
4
by: Peter W Johnson | last post by:
Hi guys, I have a problem with a datagrid record count. Here is the code:- <snip> Public Class frmMerchantDeposit Inherits System.Windows.Forms.Form Dim myconnection As New...
2
by: Rich | last post by:
Hello, Is there a way to capture the Records Affected count when performing a table Update on a Sql Server table using a DataAdapter? How is this done? Thanks, Rich
22
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source="...
2
by: yuva17raj | last post by:
hi i am using the select query with group by, so that i am getting records with more than one column so that i need to calculate the number of rows returned by the query for example with my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.