Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select to a temporary cursor
Message
De
13/12/2008 18:55:42
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01365559
Message ID:
01367230
Vues:
8
Hi Linda,

As far as I know, using the .ToTable() method of a DataView is the only easy way to get a DataTable of unique values. You'd need to use this syntax:
DataTable dtUniqueCities = MyDataSet.Tables["Customers"].DefaultView.ToTable(true, "City"); 
That will create a datatable with 1 column (City), and a unique list of the cities.

If you need to use more than one column to determine uniqueness (say, City and Zip), you'd do it like this:
DataTable dtUniqueCities = MyDataSet.Tables["Customers"].DefaultView.ToTable(true, new string[] {"City", "Zipcode"}); 
which will give you a DataTable with two columns, City and Zipcode, containing a unique combination of the two column values.

~~Bonnie



>Bonnie,
>
>Oddly enough, I just came across a need for something like this, although there may be another way to handle it. Once I have my first dataset, I would like to get the number of distinct values for a specific column in that dataset. Would I use something like these temporary tables or is there some way to query a dataset directly. I don't think I can use a RowFilter to get the number of distinct values. Thanks.
>
>
>>Hi Gerard,
>>
>>You can use the .ToTable() method of the DataView. So, something like this:
>>
>>
>>MyTable.DefaultView.RowFilter = "MyColumn = MyValue";
>>DataTable MyTempTable = MyTable.DefaultView.ToTable();
>>
>>// or //
>>
>>DataView dv = new DataView(MyTable);
>>dv.RowFilter = "MyColumn = MyValue";
>>DataTable MyTempTable = dv.ToTable();
>>
>>
>>This might not be totally what you want though, since you mentioned complicated selects, but this was my first thought off the top of my head.
>>
>>~~Bonnie
>>
>>
>>>Hi.
>>>Is there a way in .net (C#) to select to a temporary Cursor and then use this as the source
>>> of another select e.g.
>>>
>>>Select * ,.....from Tablea Into Table Temp1
>>>Select * from Temp1 into Table Temp2
>>>Select * from Temp2 into table Temp3...etc
>>>
>>>The above selects are just examples
>>>Each select is more complicated , with numerous fields and some
>>> of the selects are done for grouping purposes.
>>>
>>>Any help appreciated.
>>>regards,
>>>Gerard
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform