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
Printable View
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
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
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
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.
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
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
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