I am using datagridview in vb.net 2.0
I want to execute 2 queries.

in the first query ---
1. Can anyone tell how to check that whether the query is fetching records from the database or not.Like i want to put a condition that
if query is returning record then do this else do this.How to accomplish it?????

Another Problem---
I am willing to execute 2 queries.like....

Olecom.commandtext="select * from tablename1"
if it reurns any result then fill the record in datagridview
else dont

after that second query should be executed
Olecom.commandtext="select * from tablename2"

if it returns any result then place those record after the first query returned results in the same grid view.if the first query does not return any results then place these on top....
How to accomplish it????
I am new to vb.net...Facing a lot of problems.
Any sort of help will be appreciated..............

It is very important .Please help.I need to submit early....

Ok, how are you passing the result set to the datagridview? threw a DataReader or DataSet, their both have a method that return if there is data.

DataReader.HasRows(), return true is the reader has any data.

DataSet.Tables(0).Rows.Count Return how many rows were retrieve by the statement as integer.

hope that help you, regards.

why not join the two tables in 1 query it is more easy than making two queries and put it in 1 datagridview. but first, the two tables must be related.

My requrement is such that i want to run two different queries.after runnig first query populate he datagridview with data returned from query.

after that execute second query and place those records in datagridview after first query records....

CAn anyone help???
I will really appreciate any sort of help

In a nut shell, you want to make two queries and then put them together in a datagrid result, if that is the case, i supposed that both queries contain the same fields, you can use UNION between two statement and just past one result set to the datagrid. because I understand you want both result set in a single datagridview so the statement is going to look like this.

Select Name, LastName from Person
Union
Select Name, LastName from Vendor

Take care.

Thanks a lot.Problem got solved.Thanx for ur support

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.