Connecting Tech Pros Worldwide Forums | Help | Site Map

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

antonyliu2002@yahoo.com
Guest
 
Posts: n/a
#1: Jan 24 '06
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


Peter Bromberg [C# MVP]
Guest
 
Posts: n/a
#2: Jan 24 '06

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


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




"antonyliu2002@yahoo.com" wrote:
[color=blue]
> 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
>
>[/color]
serge calderara
Guest
 
Posts: n/a
#3: Jan 24 '06

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


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

"antonyliu2002@yahoo.com" wrote:
[color=blue]
> 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
>
>[/color]
antonyliu2002@yahoo.com
Guest
 
Posts: n/a
#4: Jan 24 '06

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


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:[color=blue]
> 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
>
>
>
>
> "antonyliu2002@yahoo.com" wrote:
>[color=green]
> > 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
> >
> >[/color][/color]

antonyliu2002@yahoo.com
Guest
 
Posts: n/a
#5: Jan 24 '06

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


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:[color=blue]
> 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
>
> "antonyliu2002@yahoo.com" wrote:
>[color=green]
> > 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
> >
> >[/color][/color]

sloan
Guest
 
Posts: n/a
#6: Jan 25 '06

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



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.

...






<antonyliu2002@yahoo.com> wrote in message
news:1138131425.061422.78150@z14g2000cwz.googlegro ups.com...[color=blue]
> 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
>[/color]


Closed Thread