[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2597
  • Last Modified:

creating a dataview with grouping from a datatable

Hi experts,

I have an application that displays product usage information by year in a datagridview.  This typically displays about 150k of records.  I am trying to create an option to group by product (meaning sum up all the years info).  I would like for the user to just select a radio button to change the grouping.  I can run different SQL statments each time but thought there may be a better way, since I have the data already.

Can I create a new view on the table that includes the grouping or is there a way to run an sql statement against the datatable instead of requering the sql server?

Thanks

Mike
0
EXTRHMAN
Asked:
EXTRHMAN
1 Solution
 
TimCotteeCommented:
I guess the simple answer to that is no, you cannot run a query against the datatable and I am not aware of a solution that allows the grid to do the summation dynamically.

One possibility is to return two resultsets from your initial query, one being the unsummed data and the other the summary data. You can then simply switch datatables on the radio button event to avoid having to requery each time this is clicked. It might slightly increase your load time but will avoid the requerying.
0
 
DhaestCommented:
Currently, .Net2.0 DataGridView control did not provide the build-in row
grouping function, and I do not think there is any easy way to customizing
this function.

Perhaps you can perform a group by in your datatable and rebind it.
HOW TO: Implement a DataSet GROUP BY Helper Class in Visual Basic .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;325685
0
 
EXTRHMANAuthor Commented:
Thanks Dhaest
That was an excellent find and it worked like a charm.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now