|
-
Jan 8th, 2008, 09:51 PM
#1
Thread Starter
Addicted Member
Another select statement
Hi gurus
I have the following selct statement
stringconnec= "select las_name from Table where condition"
How do I go and check if the select statement came back with a result or not
Thanks a bunch
-
Jan 8th, 2008, 10:10 PM
#2
Frenzied Member
Re: Another select statement
rs.recordcount is one way. This depends on which cursor you use too. I believe you use a snapshot cursor will give the recordcount.
the other is:
strSQL="SELECT COUNT(*) FROM TableA
WHERE BlaBla = 11111"
msgbox rs.Field(0).value
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
-
Jan 9th, 2008, 12:06 AM
#3
Thread Starter
Addicted Member
Re: Another select statement
L.
Thanks for the replay, but I have a question
how count(*) will help check if a result came back.
I am looking for a particular record last_name (smith) within the table if there is a smith the select statement will bring the record but if not the select statement will nothing is here where I need to check if something came back or not
it seems like count(*) will tell me if there are records on a table. am I missing something
Thanks for battling
-
Jan 9th, 2008, 01:02 AM
#4
Frenzied Member
Re: Another select statement
so do it like this:
strSQL="SELECT * FROM TableA
WHERE LastName='Smith'"
run that throught the recordset with the cursor set to static.
once it is open, do a recordset.recordcount and that will give you the count.
Pretty much similar to what I described in the previous post.
I'll Be Back!
T-1000
Microsoft .Net 2005
Microsoft Visual Basic 6
Prefer using API
-
Jan 9th, 2008, 08:33 AM
#5
Re: Another select statement
If using ADO and VB6 test for recordset EOF and BOF if they are true then No records.
If using ADO.Net and VB.Net for Datareaders check the .HasRows property. For DataSets test if the dataset.Table(#).Rows.RowCount() > 0
Sometimes the Programmer
Sometimes the DBA
Mazz1
-
Jan 9th, 2008, 10:01 AM
#6
Thread Starter
Addicted Member
Re: Another select statement
Gary/L
Thanks a bunch, here I am on my first application using .net and having this kind of problems, so thanks for battling with me here
I was trying to get the same prop or meth from datatable.
I am using sqlclient to connect to the sql server
so I have a sqladapter.fill(ds) where ds is my datatable object
then I populate my datagrid with my ds
But before I do all this I would like to know if the select statement comes back with something or not
Thanks again
-
Jan 9th, 2008, 10:25 AM
#7
Re: Another select statement
I would look at
vb.net Code:
DataGridView1.DataSource = ds.Tables(0)
If ds.Tables(0).Row.Count() = 0 Then
'Do Something Else
MessageBox.Show("No Records Found!","No Data")
End If
Sometimes the Programmer
Sometimes the DBA
Mazz1
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|