|
| Dataview, Dataset - Select Distinct |
|
|
|
|
| Messages |
|
Related Types |
This message was discovered on microsoft.public.dotnet.distributed_apps.
| Dianna |
I don't understand why the dataview or the dataset does not have a 'Select Distinct' option. They both can do so much to filter the data except that. The article Microsoft has 326176 works, but not if you need to select distinct on multiple fields.
Does anyone have any suggestions?
Thanks, Dianna
|
|
|
| |
|
| |
| |
| Paul N |
Hi there,
I always used actual SQL input to pull my data back. In our situation here, people use massively varying queries, so dynamic SQL is built up at run time, and I build this in the code behind the aspx pages. Once the SQL has been built, however, I send it to a DBAccess object which i always build for any of these web applications i build. I attach a sample of some of the DBAccess code, as well as some code calling it. I hope this helps.
'DBAccess code - strConn is the connection string, inSQL is the SQL input to the function
Public Function doQuery(inSQL) As DataSet ds = New DataSet() da = New OleDb.OleDbDataAdapter(inSQL, strConn) da.Fill(ds, "results") Return ds End Function
'in the calling object
private sub MyAction() 'myDB is a DBAccess object, created globally for this page in page_load myDataSet = myDB.doQuery("SELECT DISTINCT NAME, ADDRESS FROM ADDRESS_BOOK WHERE PURCHASE_AMOUNT > 1000") myDataGrid.DataSource = myDataSet myDataGrid.DataBind() end sub
|
|
|
| |
|
| |
| |
| Dianna |
Hi Paul, Thanks for your help. The data I am using is not coming from a database, its coming from Excel. So, I kind of never really use any SQL (I wish I did, then I wouldn't have this problem).
Thanks, Dianna
|
|
|
| |
|
|
| |
|
|
| |
| Nageswara Reddy |
Hi There, The following code will work for you. The assupmtion is that you have the data in a table _DataTable
DataTable PurgedDataTable = _DataTable.Clone(); DataColumn []_Columns = new DataColumn[PurgedDataTable.Columns.Count]; for (int i =0 ; i< _DataTable.Columns.Count ; i++) { _Columns[i]= PurgedDataTable.Columns[i]; } UniqueConstraint _UniqueConstraint = new UniqueConstraint(_Columns); PurgedDataTable.Constraints.Add(_UniqueConstraint);
for (int i =0 ; i< _DataTable.Rows.Count ; i++) { try { PurgedDataTable.ImportRow(_DataTable.Rows[i]); } catch(Exception ex) { // Keep quite } } -------------------------------- From: Nageswara Reddy
|
|
|
| |
|
| |
|
|
|
|
|
|
|
|
BootFX
Reliable and powerful .NET application framework. |
|
|
|
|
|
|