Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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

Reply to this message...
Vote that this is a GOOD answer...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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

Reply to this message...
Vote that this is a GOOD answer...
 
Outlook interop - stopping user properties appearing on Outlook message print
Seriously, why is “cut and paste” majorly newsworthy???
 
    
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

Reply to this message...
Vote that this is a GOOD answer...
 
 
    
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
Reply to this message...
Vote that this is a GOOD answer...
 
Email Archiving and Email Filing - what’s the difference?
Web-based task/todo list management
 
 
System.Data.DataColumn
System.Data.DataSet
System.Data.DataTable
System.Data.OleDb.OleDbDataAdapter
System.Data.UniqueConstraint




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734