469,646 Members | 1,340 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

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 6008
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Darko Jovisic | last post: by
5 posts views Thread by Stanley Sinclair | last post: by
1 post views Thread by randall g | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
3 posts views Thread by =?Utf-8?B?S2F5xLFoYW4=?= | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.