473,796 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query Group Dataset

I have a dataset / datatable in memory and i would like to run a query
against that to create another in memory datatable or dataview. In this
case I have a bunch of data... and i want to run a 'grouping' select query
where i just get all items grouped together for example:

Existing in memory datatable (2 fields, qty and desc):
Record 1: Qty: 23 Desc: Bananas
Record 2: Qty 10 Desc: Strawberries
Record 3: Qty 23 Desc: Bananas
Record 4: Qty 18 Desc: Grapes

I want to run a group query on field 'Desc' to give me:
Record 1: Bananas
Record 2: Strawberries
Record 3: Grapes

Any ideas? I know how to do this if the data is in an sql database.. but
how do i run a query against an in memory dataset?

Thanks in advance!
Chris
ct******@pierce associates.com
Nov 20 '05 #1
1 1561
Hi Chris,

Thanks for posting. Is it possible that we "select" the new table directly
from the SQL Server data?

SELECT DISTINCT Desc FROM Fruit
(Here I assume the table name is "Fruit")

If not, to generate the new table from an existing DataTable as you
described, we are not able to use SQL statements directly. However, we can
try the following code to enumerate and manipulate the tables:

Dim dt As New DataTable
Dim dr As DataRow
'Define the table structure
dt.Columns.Add( "Desc", GetType(System. String))
'Enumerate the original table DataSet1.Tables ("Fruit")
For Each dr In DataSet1.Tables ("Fruit").Ro ws
Dim ndr As DataRow
'Set the flag
Dim DuplicatedFound As Boolean
DuplicatedFound = False
'Enumerate the new table to check for duplicated values
For Each ndr In dt.Rows
'If duplicated value found.
If dr("Desc") = ndr("Desc") Then
'Set the flag. We may also add some additional code
here (e.g. to sum the Qty)
DuplicatedFound = True
Exit For
End If
Next
'Add the row to the new table if no duplicated found
If (Not DuplicatedFound ) Then
Dim NewRow(0) As Object
NewRow(0) = dr("Desc")
dt.Rows.Add(New Row)
End If
Next

At the end of the execution, the variable "dt" will point to the new
DataTable you need.

I hope this helps.

Regards,

Felix Wang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 20 '05 #2

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

Similar topics

1
2065
by: John Sway | last post by:
I'm writing a web-based "Query analyser" tool for our company intranet. It allows a user to type any SQL statement in a form, and execute it over the Web. The SQL can be a query that returns results (e.g: SELECT * FROM members) or it can be a T-SQL (e.g: UPDATE/DELETE/INSERT). What I want to know is, is there any way using either SQLCommand or DataSet or any of the other ADO.NET classes to determine what kind of query it is, BEFORE...
7
4032
by: Phin | last post by:
I need your HELP! I've seen all the posts on using Crystal Reports within vs.net (vb.net) and changing a SQL query at runtime. When I tried to pass in a dataset into the crystal report at runtime, the report still showed the results from the default query (from within the Crystal Report). Then I tried the XSD solution where you define a dataset (that mataches the database and the Crystal Report) and have the Crystal Report use this....
1
1939
by: dan_williams | last post by:
I am attempting to create a ASP.NET report whereby users can specify which columns they wish to be able to view depending on the options they select from a CheckBoxList. I have 4 tables, ClientGroups, Clients, Bookings & Depts. ClientGroups Clients Bookings -------------- ------------------ ------------------- cgId PK int ClientId PK int BookingId PK int cgName varchar ClientName...
3
1666
by: Hyphessobricon | last post by:
Hallo, Indeed, a count of a query with a group by function gives more records than there are and so for-next structures don't function. How is this to be mended. Anyone? Everyone in fact. Answers are greatly appreciated. -- mvg Hyphessobrycon
3
1971
by: phonl | last post by:
I am a vb6 ADO developer looking at vb.net 2005 and ADO2.net. I used the vb.net 2005 data wizard to bind some controls to a database. Now I want to run a select query and have the bound controls reflect the change from the query. How would I do that? The wizard created a TableAdapter, BindingSource, and DataSet. Somehow I need to run feed them a select query to update the data.
3
1753
by: Parasyke | last post by:
I have a complicated query that is giving me duplicate records for some of the returned records. Underwriter name is what I don't want to duplicate. Any clues? Thanks for any help! SELECT qryUnderwriters.UWID, qryUnderwriters.UWName, qryUnderwriters.JobTitle, qryUnderwriters.BUName, qryUnderwriters.EmployHireDate, qryUnderwriters.ApptStartDate, qryUnderwriters.TermDate, qryUnderwriters.EmployTypeCode, qryUnderwriters.Active,...
2
17653
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How can I run this query against a table in my Access database? I don't know hwo to use it in C#. In VB I would use .Recordset = "some sql statement". How do I do this in C#? //I get a vlaue form a cell and apply it to the SQL statement commandCol = scriptDataGridView.FormattedValue.ToString(); string sCommand = "SELECT CommandString FROM Commands WHERE CommandName = " + commandCol; //This reutne a valie SQL statement which will return...
4
2623
by: dsdevonsomer | last post by:
Hello, I have one simple query joining two tables with left outer join on 3 fields and using MIN on two fields. These two tables have lot of data about 3 mil in total. I am trying to migrate db from MS Access to SQL 2005. I get about 689000 rows in SQL Server, vs 863000 rows in MS Access. SELECT T1., T1., T2., MIN ( T1.), MIN(T1. ), T1.COUNT
1
1361
by: usawargamer | last post by:
My dataset looks like this: 2 groups (G1 and G2) of 4 items each Group G1 contains id value A1 9 A2 7 B1 3 B2 2
0
10231
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10176
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9054
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6792
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5443
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5576
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4119
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3733
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2927
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.