473,473 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Create 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******@pierceassociates.com
Nov 20 '05 #1
1 1548
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").Rows
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(NewRow)
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
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...
7
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...
1
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,...
3
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....
3
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...
3
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...
2
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...
4
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...
1
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...

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.