954,517 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

dispalying data in grid from multiple queries

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

Eliza123
Newbie Poster
5 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

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.

jbisono
Posting Pro in Training
442 posts since May 2009
Reputation Points: 71
Solved Threads: 59
 

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.

c0deFr3aK
Junior Poster in Training
71 posts since Mar 2009
Reputation Points: 11
Solved Threads: 10
 

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

Eliza123
Newbie Poster
5 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

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.

jbisono
Posting Pro in Training
442 posts since May 2009
Reputation Points: 71
Solved Threads: 59
 

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

Eliza123
Newbie Poster
5 posts since Mar 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You