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

Multiple result sets in one DataGridView

I am wondering if someone could provide a code sample (or just a suggested
approach) on how to fill a single DataGridView with multiple result sets. For
example, this statement returns a one-line result set for each table in the
database:

EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"

It would be handy to be able to put them all into one DataGridView. I would
like to be able to handle an arbitrary SQL statement; above is just one
example. The code I am currently using is:
----------------------------------------------
DataTable dataTable = new DataTable();
SqlDataAdapter aviAdapter = new SqlDataAdapter(query, connection);
aviAdapter.Fill(dataTable);
aviDataTableBindingSource.DataSource = dataTable;
aviDataTableBindingSource.DataMember = null;
aviDataGridView.DataSource = aviDataTableBindingSource;
----------------------------------------------
....but this only operates on the first result set.

Apr 23 '07 #1
3 6200
Hi Michael ,

Based on my understanding, you want to display multiple datatables data in
a single DataGrid.

To achieve this effect, we have several ways, I will list some below:
1. Use a JOIN helper class to join the 2 tables together, then bind it to
the DataGrid. The 2 KBs below show the joining at DataTable level and
DataView level:
"HOW TO: Implement a DataSet JOIN helper class in Visual C# .NET"
http://support.microsoft.com/default...b;en-us;326080
"HOW TO: Implement a Custom DataView Class in Visual Basic .NET"
http://support.microsoft.com/default...b;en-us;325682
2. We can extend the binding expression to recognize another table's
binding field at DataGridTextBoxColumn UI level, see the KB below:
"HOW TO: Extend the Windows Form DataGridTextBoxColumn to Display Data From
Other Tables by Using Visual C# .NET"
http://support.microsoft.com/default...b;en-us;319076

Although they are intended for DataGrid, however, the principle is the same
for DataGridView. Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 8 '07 #2
Your references will probably take care of what I need; thank you.

""Jeffrey Tan[MSFT]"" wrote:
Hi Michael ,

Based on my understanding, you want to display multiple datatables data in
a single DataGrid.

To achieve this effect, we have several ways, I will list some below:
1. Use a JOIN helper class to join the 2 tables together, then bind it to
the DataGrid. The 2 KBs below show the joining at DataTable level and
DataView level:
"HOW TO: Implement a DataSet JOIN helper class in Visual C# .NET"
http://support.microsoft.com/default...b;en-us;326080
"HOW TO: Implement a Custom DataView Class in Visual Basic .NET"
http://support.microsoft.com/default...b;en-us;325682
2. We can extend the binding expression to recognize another table's
binding field at DataGridTextBoxColumn UI level, see the KB below:
"HOW TO: Extend the Windows Form DataGridTextBoxColumn to Display Data From
Other Tables by Using Visual C# .NET"
http://support.microsoft.com/default...b;en-us;319076

Although they are intended for DataGrid, however, the principle is the same
for DataGridView. Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 9 '07 #3
Ok, if you need further help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

May 10 '07 #4

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

Similar topics

2
by: Darko Jovisic | last post by:
Hi! Another silly question: If a stored procedure returns multiple result sets, how do I choose the one I want to insert into a table? For example sp_spaceused returns two result sets if...
4
by: randy.p.ho | last post by:
Using JDBC, is there a way to call a stored procedure with multiple return values? Thanks.
3
by: wxbuff | last post by:
I have a report based on our product names that consists of two parts. Both insert data into a temporary table. 1. A single grouped set of results based on all products 2. Multiple tables based...
5
by: Stanley Sinclair | last post by:
I have a need to return multiple result sets from a stored procedure. Want that SP to call others to get the data. Win2003, db2 8.1.5. Can't figure out how to handle open cursors, and return...
1
by: randall g | last post by:
I have a stored procedure which returns multiple result sets, enclosing each in its own tag. This works in ADO but not ADO.NET, where an error is returned by ExecuteXmlReader: "Invalid command...
15
by: AussieRules | last post by:
Hi, I have a need to do two selects against to stored proc's in my SQL db. At the moment, each SP is called and two different dataset are populate. Thats two round trips to the SQL server. ...
4
by: Liz | last post by:
Anyone have any info on how you can fill a DataSet with mutiple result sets from a SQL batch ? I know with a dataReader you can use the nextResult method but I'm lost on how you do this with a...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
3
by: =?Utf-8?B?S2F5xLFoYW4=?= | last post by:
In my project,i added datagridview to my form , i transfered my table to datagridview and added multiple rows and when i called dataadapther.update ,,result is ok. But when i tried it for the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.