473,804 Members | 3,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

select from dataset

hi all. I have a dataset and would like to do something like "select
distinct field1, field2 from fields" against the dataset. I do not
have the option of creating a new database table and selecting from
that table. Nor do I have the option of changing how the dataset is
populated. I need to select distinct from the dataset that I have.
Any suggestions?

May 9 '07 #1
5 6445
<ju************ ******@yahoo.co mwrote in message
news:11******** *************@e 65g2000hsc.goog legroups.com...
hi all. I have a dataset and would like to do something like "select
distinct field1, field2 from fields" against the dataset. I do not
have the option of creating a new database table and selecting from
that table. Nor do I have the option of changing how the dataset is
populated. I need to select distinct from the dataset that I have.
Any suggestions?
Unfortunately, the Select() in the DataTable does not provide the
Distinct operator. You will have to filter the rows with a loop in your own
code. One way to do it is to first sort the data on the fields that need to
be distinct (for instance, using Sort by means of an interposed DataView),
and then iterate over all records with a for loop, extracting only those
records whose fields do not match those of the record processed in the
previous iteration.
May 9 '07 #2
On May 9, 8:07 am, "Alberto Poblacion" <earthling-
quitaestoparaco ntes...@poblaci on.orgwrote:
<justanothernew bie...@yahoo.co mwrote in message

news:11******** *************@e 65g2000hsc.goog legroups.com...
hi all. I have a dataset and would like to do something like "select
distinct field1, field2 from fields" against the dataset. I do not
have the option of creating a new database table and selecting from
that table. Nor do I have the option of changing how the dataset is
populated. I need to select distinct from the dataset that I have.
Any suggestions?

Unfortunately, the Select() in the DataTable does not provide the
Distinct operator. You will have to filter the rows with a loop in your own
code. One way to do it is to first sort the data on the fields that need to
be distinct (for instance, using Sort by means of an interposed DataView),
and then iterate over all records with a for loop, extracting only those
records whose fields do not match those of the record processed in the
previous iteration.
thanks, that's what I suspected, but was hoping for a more sql like
capabilty.

May 9 '07 #3
I don't know (highly doubt) that this will help you now, but with C# 3.0
and .NET 3.5, you will be able to do this (both in beta right now). It will
allow you to do something like this:

// Your data table is in dt
IEnumerable<Dat aRowrows = dt.AsEnumerable ().Distinct();

Then, you will get just distinct rows from the datatable.

If you need to load it back into another datatable for use, you can do
this:

// This can be typed as well. If so, use the overload which takes a
datatable which has
// a matching structure.
DataTable newDt = dt.AsEnumerable ().Distinct().C opyToDataTable( );

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

<ju************ ******@yahoo.co mwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
On May 9, 8:07 am, "Alberto Poblacion" <earthling-
quitaestoparaco ntes...@poblaci on.orgwrote:
><justanotherne wbie...@yahoo.c omwrote in message

news:11******* **************@ e65g2000hsc.goo glegroups.com.. .
hi all. I have a dataset and would like to do something like "select
distinct field1, field2 from fields" against the dataset. I do not
have the option of creating a new database table and selecting from
that table. Nor do I have the option of changing how the dataset is
populated. I need to select distinct from the dataset that I have.
Any suggestions?

Unfortunately, the Select() in the DataTable does not provide the
Distinct operator. You will have to filter the rows with a loop in your
own
code. One way to do it is to first sort the data on the fields that need
to
be distinct (for instance, using Sort by means of an interposed
DataView),
and then iterate over all records with a for loop, extracting only those
records whose fields do not match those of the record processed in the
previous iteration.

thanks, that's what I suspected, but was hoping for a more sql like
capabilty.

May 9 '07 #4
Look in Microsoft visual studio 2005 documention ToTable method for
DataTable

On 9 May 2007 04:48:24 -0700, ju************* *****@yahoo.com wrote:
>hi all. I have a dataset and would like to do something like "select
distinct field1, field2 from fields" against the dataset. I do not
have the option of creating a new database table and selecting from
that table. Nor do I have the option of changing how the dataset is
populated. I need to select distinct from the dataset that I have.
Any suggestions?
May 10 '07 #5
cvvc

"ju************ ******@yahoo.co m" wrote:
hi all. I have a dataset and would like to do something like "select
distinct field1, field2 from fields" against the dataset. I do not
have the option of creating a new database table and selecting from
that table. Nor do I have the option of changing how the dataset is
populated. I need to select distinct from the dataset that I have.
Any suggestions?

May 15 '07 #6

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

Similar topics

0
1492
by: JJ | last post by:
Hi I basically create a dataset and read in a schema file into the dataset. Then when done saving a record to the dataset I save to file as diffgram. When I come back in and recreate the dataset I need to find a particular record that is in the dataset. I do this with the following code <code private void FindTodaysDSRec( string sDate, sRecFind
3
10215
by: gh | last post by:
I have made the following stored procedure with the following select statement select * from user select * from order, orderdetail where order.id=orderdetail.id I know I can uses DataReader class to get data from the store procedue. However, is there any way for me to use DataAdapter to get the data and put it in separate DataTables in a DataSet?
1
11585
by: Ahmet Karaca | last post by:
Hi. myds.Reset(); mycommand.SelectCommand.CommandText= "Select att1 from Ing as Ingredient, Pro as Product "+ "where Pro.ad='apple' and Pro.id=Ing.id"; mycommand.Fill(myds, "Product"); // Here is the problem listbox.DataSource = myds.Tables.DefaultView; // Here again listbox.DataTextField = "invid"; // Here again listbox.DataBind(); mycon.Close()
2
1260
by: soulcode | last post by:
Hi Guys, Yesterday i was playing around with some code where I would read an xml file into a dataset... '*********************************** Dim ds as dataset ds.readxml("test.xml") '***********************************
1
4042
by: Diffident | last post by:
Hello All, I am trying to filter rows in a datatable based on filtercriteria and sortcriteria using the datatable.select() method. I am encountering a strange behavior in this process. Here is what I am trying to do... ---------
7
3004
by: Matt Jensen | last post by:
Howdy Fairly simple question I think, I presume the answer is no it can't be reused for 2 *SELECT* statements, but just hoping for clarification. Just asking in the interests of trying to minimise code. i.e. if the SqlDataAdapter uses a connection to the one database for a select statement and I want to do a second select statement on exactly the same database, can I reuse the SqlDataAdapter? I ask because I want to put both 'select'...
4
1337
by: bill salkin | last post by:
The code below creates a dataset containing a table called "Customers" from the Northwind database Later on in my code, after the database connection is closed, I need to access this dataset to get all records with "ContactTitle" = 'Owner' and "City" = 'London'. I have tried using the SELECT and Find methods of dataset techbnology but I can't make them work with multi- criteria queries.Help!
11
49205
by: Nathan | last post by:
Is there any way to do a DataSet.Select() statement and use more than one selection "query"? For instance, instead of just selecting all rows where the IDNum is greater than 32 with DataSet.Select("IDNum > 32"), select all rows where the IDNum > 32 and the Region = Midwest. Is this possible?
11
3950
by: MurdockSE | last post by:
Greetings. My Situation: // I have an .xml file that I am reading into a dataset in the following code - DataSet ds = new DataSet("MyDataset"); ds.ReadXml(@"c:\data\"+cmyxmlfilename);
3
25690
by: Jeff | last post by:
hey ..NET 2.0 I have a datatable which consist of 3 columns (int, date, value). This DataTable have 3 rows, the values of the "date" ("date" column is of datetime datatype) column is: 2007-09-15 00:00:00.000 2007-10-15 00:00:00.000 2007-11-15 00:00:00.000
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10571
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10326
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
10317
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
9143
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...
1
7615
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6851
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
5520
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...
1
4295
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

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.