Click here to Skip to main content
15,920,468 members
Home / Discussions / C#
   

C#

 
GeneralRe: End of line Pin
Nguyen Vu Cuong23-Mar-04 16:42
Nguyen Vu Cuong23-Mar-04 16:42 
GeneralDesktop Control Pin
Member 69108923-Mar-04 15:04
Member 69108923-Mar-04 15:04 
GeneralRe: Desktop Control Pin
Heath Stewart23-Mar-04 18:08
protectorHeath Stewart23-Mar-04 18:08 
GeneralRe: Desktop Control Pin
Anonymous24-Mar-04 14:09
Anonymous24-Mar-04 14:09 
GeneralRe: Desktop Control Pin
Heath Stewart24-Mar-04 17:00
protectorHeath Stewart24-Mar-04 17:00 
GeneralDistinct - DataView/DataTable Pin
Ruchi Gupta23-Mar-04 13:57
Ruchi Gupta23-Mar-04 13:57 
GeneralRe: Distinct - DataView/DataTable Pin
Heath Stewart23-Mar-04 14:09
protectorHeath Stewart23-Mar-04 14:09 
GeneralRe: Distinct - DataView/DataTable Pin
Ruchi Gupta23-Mar-04 14:41
Ruchi Gupta23-Mar-04 14:41 
HI,

Similar to what you suggested, I got an article on Microsoft website. It works but the limitation is what if DISTINCT is to be applied on multiple columns

http://support.microsoft.com/default.aspx?scid=kb;en-us;326176

Add the following Private method to the class definition. This method is the same as the method that is used in other DataSetHelper articles. It is used to compare field values (including NULL).
private bool ColumnEqual(object A, object B)<br />
{<br />
	<br />
        // Compares two values to see if they are equal. Also compares DBNULL.Value.<br />
        // Note: If your DataTable contains object fields, then you must extend this<br />
        // function to handle them in a meaningful way if you intend to group on them.<br />
			<br />
        if ( A == DBNull.Value && B == DBNull.Value ) //  both are DBNull.Value<br />
            return true; <br />
        if ( A == DBNull.Value || B == DBNull.Value ) //  only one is DBNull.Value<br />
            return false; <br />
        return ( A.Equals(B) );  // value type standard comparison<br />
}

Add the following Public method to the class definition. This method copies unique values of the field that you select into a new DataTable. If the field contains NULL values, a record in the destination table will also contain NULL values.
public DataTable SelectDistinct(string TableName, DataTable SourceTable, string FieldName)<br />
{	<br />
        DataTable dt = new DataTable(TableName);<br />
        dt.Columns.Add(FieldName, SourceTable.Columns[FieldName].DataType);<br />
			<br />
        object LastValue = null; <br />
        foreach (DataRow dr in SourceTable.Select("", FieldName))<br />
        {<br />
            if (  LastValue == null || !(ColumnEqual(LastValue, dr[FieldName])) ) <br />
            {<br />
                LastValue = dr[FieldName]; <br />
                dt.Rows.Add(new object[]{LastValue});<br />
            }<br />
        }<br />
        if (ds != null) <br />
            ds.Tables.Add(dt);<br />
        return dt;<br />
}

GeneralRe: Distinct - DataView/DataTable Pin
Heath Stewart23-Mar-04 18:00
protectorHeath Stewart23-Mar-04 18:00 
GeneralXML Serialization and ArrayLists Pin
raindog23-Mar-04 13:23
raindog23-Mar-04 13:23 
GeneralRe: XML Serialization and ArrayLists Pin
Heath Stewart23-Mar-04 13:45
protectorHeath Stewart23-Mar-04 13:45 
GeneralWindows XP P2P SDK wrapped in .Net Pin
schnee2k323-Mar-04 13:03
schnee2k323-Mar-04 13:03 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
Heath Stewart23-Mar-04 13:34
protectorHeath Stewart23-Mar-04 13:34 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
schnee2k323-Mar-04 13:40
schnee2k323-Mar-04 13:40 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
Matthew Hazlett23-Mar-04 14:48
Matthew Hazlett23-Mar-04 14:48 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
leppie24-Mar-04 6:17
leppie24-Mar-04 6:17 
GeneralRe: Windows XP P2P SDK wrapped in .Net Pin
schnee2k324-Mar-04 13:07
schnee2k324-Mar-04 13:07 
QuestionHow to change url of running iexplorer instance? Pin
ckl_8823-Mar-04 12:47
ckl_8823-Mar-04 12:47 
AnswerRe: How to change url of running iexplorer instance? Pin
Heath Stewart23-Mar-04 13:01
protectorHeath Stewart23-Mar-04 13:01 
GeneralRe: How to change url of running iexplorer instance? Pin
ckl_8823-Mar-04 13:50
ckl_8823-Mar-04 13:50 
GeneralRe: How to change url of running iexplorer instance? Pin
Heath Stewart23-Mar-04 14:01
protectorHeath Stewart23-Mar-04 14:01 
GeneralStrange problem with ownerdraw listbox Pin
Anders Molin23-Mar-04 12:41
professionalAnders Molin23-Mar-04 12:41 
GeneralRe: Strange problem with ownerdraw listbox Pin
Heath Stewart23-Mar-04 13:05
protectorHeath Stewart23-Mar-04 13:05 
GeneralRe: Strange problem with ownerdraw listbox Pin
Anders Molin23-Mar-04 13:22
professionalAnders Molin23-Mar-04 13:22 
GeneralRe: Strange problem with ownerdraw listbox Pin
Heath Stewart23-Mar-04 13:37
protectorHeath Stewart23-Mar-04 13:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.