473,387 Members | 1,899 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,387 software developers and data experts.

How to cram into one DataGrid results from more than 1 queries?

I want to put results from more than 1 sql queries into a signle
datagrid,

For example, in my web application, I submit this following query to my
oracle database:

Select NetID, Firstname, Lastname from Student;

Then I put the result into my DataGrid. This is successful.

Following this, I issue the following query:

Select NetID, Firstname, Lastname from Faculty;

and I want to append the result to the same DataGrid.

Right now, my application is apparently overwriting the previous
records inserted into the DataGrid.

How can I append the result of the second query to the same DataGrid?
Thanks

Jan 24 '06 #1
5 1438
The syntax for a SQL UNION QUERY:

select NetID,Firstname, Lastname from Student
UNION
select NetID,Firstname, Lastname from Faculty;

This will return a single resultset which you can bind to your grid.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"an***********@yahoo.com" wrote:
I want to put results from more than 1 sql queries into a signle
datagrid,

For example, in my web application, I submit this following query to my
oracle database:

Select NetID, Firstname, Lastname from Student;

Then I put the result into my DataGrid. This is successful.

Following this, I issue the following query:

Select NetID, Firstname, Lastname from Faculty;

and I want to append the result to the same DataGrid.

Right now, my application is apparently overwriting the previous
records inserted into the DataGrid.

How can I append the result of the second query to the same DataGrid?
Thanks

Jan 24 '06 #2
You could also fill the same dataset for your both querry before binding it
to you grid.
As tables name are different they will be added to the dataset table
collection
Then when it will be bind to your grid you will have both querry

Drawback in that solution is than you will have to deploy you table tree in
grid view

"an***********@yahoo.com" wrote:
I want to put results from more than 1 sql queries into a signle
datagrid,

For example, in my web application, I submit this following query to my
oracle database:

Select NetID, Firstname, Lastname from Student;

Then I put the result into my DataGrid. This is successful.

Following this, I issue the following query:

Select NetID, Firstname, Lastname from Faculty;

and I want to append the result to the same DataGrid.

Right now, my application is apparently overwriting the previous
records inserted into the DataGrid.

How can I append the result of the second query to the same DataGrid?
Thanks

Jan 24 '06 #3
Hmm, that is a great solution, I thought about this actually, but I am
not a good DB person, so I did not come up with the SQL Union solution.

Thanks a lot!

Peter Bromberg [C# MVP] wrote:
The syntax for a SQL UNION QUERY:

select NetID,Firstname, Lastname from Student
UNION
select NetID,Firstname, Lastname from Faculty;

This will return a single resultset which you can bind to your grid.

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"an***********@yahoo.com" wrote:
I want to put results from more than 1 sql queries into a signle
datagrid,

For example, in my web application, I submit this following query to my
oracle database:

Select NetID, Firstname, Lastname from Student;

Then I put the result into my DataGrid. This is successful.

Following this, I issue the following query:

Select NetID, Firstname, Lastname from Faculty;

and I want to append the result to the same DataGrid.

Right now, my application is apparently overwriting the previous
records inserted into the DataGrid.

How can I append the result of the second query to the same DataGrid?
Thanks


Jan 24 '06 #4
This sounds like a great solution, too, but I am new to the .NET
framework, would you mind briefing me a little bit about deploying
table tree in grid view? What is a table tree?

Or if you could please just give me a link, that would save you some
time.

Thanks.

serge calderara wrote:
You could also fill the same dataset for your both querry before binding it
to you grid.
As tables name are different they will be added to the dataset table
collection
Then when it will be bind to your grid you will have both querry

Drawback in that solution is than you will have to deploy you table tree in
grid view

"an***********@yahoo.com" wrote:
I want to put results from more than 1 sql queries into a signle
datagrid,

For example, in my web application, I submit this following query to my
oracle database:

Select NetID, Firstname, Lastname from Student;

Then I put the result into my DataGrid. This is successful.

Following this, I issue the following query:

Select NetID, Firstname, Lastname from Faculty;

and I want to append the result to the same DataGrid.

Right now, my application is apparently overwriting the previous
records inserted into the DataGrid.

How can I append the result of the second query to the same DataGrid?
Thanks


Jan 24 '06 #5

Look up DataSet.Merge.
It does well for merging ROWS.

I'd go for a strongly typed dataset also.
Add New Item / DataSet
rename it "MyFirstStrongDS"

Click "XML" at the bottom of the Designer.

Its too much to explain, but I'll post the code.

Copy and Paste this in:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="MyFirstStrongDS" xmlns=""
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:codegen="urn:schemas-microsoft-com:xml-msprop">
<xs:element name="MyFirstStrongDS" msdata:IsDataSet="true">
<xs:complexType>
<xs:choice maxOccurs="unbounded">

<xs:element name="Publishers">
<xs:complexType>
<xs:sequence>
<xs:element name="NetID" type="xs:string" minOccurs="0" />
<xs:element name="Firstname" type="xs:string" minOccurs="0" />
<xs:element name="Lastname" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>

</xs:element>
</xs:schema>

In your code, you'll have
MyFirstStrongDS ds1 = //code to populate the DS from the Student table

MyFirstStrongDS ds2 = //code to populate the DS from the Faculty table

ds2.Merge(ds1);
Console.WriteLine(ds2.GetXml());
Something like that.
The strongly typed is optional, but the .Merge is a good place for you, if
you don't control the database, and can't create a UNION query.

...


<an***********@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I want to put results from more than 1 sql queries into a signle
datagrid,

For example, in my web application, I submit this following query to my
oracle database:

Select NetID, Firstname, Lastname from Student;

Then I put the result into my DataGrid. This is successful.

Following this, I issue the following query:

Select NetID, Firstname, Lastname from Faculty;

and I want to append the result to the same DataGrid.

Right now, my application is apparently overwriting the previous
records inserted into the DataGrid.

How can I append the result of the second query to the same DataGrid?
Thanks

Jan 25 '06 #6

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

Similar topics

3
by: Matt O'Donnell | last post by:
Does anyone know how I can 'join' the results of one SQL query to the bottom of another? Eg. I have two queries: 1. SELECT Name, Surname FROM People WHERE Surname = Smith NAME ...
2
by: John Smith | last post by:
Hey folks, I'm writing a Windows application which has many forms which have Datagrids on them to display data. These datagrids will not be editable in anyway. They are there to just view the...
5
by: BBFrost | last post by:
Win2000 ..Net 1.1 SP1 c# using Visual Studio Ok, I'm currently in a "knock down - drag out" tussle with the .Net 1.1 datagrid. I've come to realize that a 'block' of rows highlighted within...
0
by: Andy | last post by:
Hi, I want to fill a datagrid with results from a team. I am looking to fill datagrids with queries similar to "The most recent 5 results", or "All youth team results". It shouldn't be that hard...
6
by: Jim | last post by:
Can someone, please, show me how to display the results of a stored procedure in a VB.NET datagrid on a winform? I'm a newbie. Here's my SQL 2000 stored precedure that returns the status of...
3
by: simchajoy2000 | last post by:
Hi, I am using a datagrid which contains a dataset with several tables and I am experiencing an inexplicable behavior that I am unable to resolve. Perhaps it's due to the complexity of my...
0
by: | last post by:
I have a question about spawning and displaying subordinate list controls within a list control. I'm also interested in feedback about the design of my search application. Lots of code is at the...
1
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form...
1
by: Pedro Rosas Silva | last post by:
Hi all, I have a datagrid in an ASP.Net 1.1 web application which is binded to an HashTable. The grid has several columns and I want to sort the results by one of those columns. Are you aware...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.