-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: shahkalpesh
Message 7 in Discussion

        DataTable distinct(DataTable dtSource, DataColumn dcolDistinct, String 
strNewTable)
        {
                String strCol = dcolDistinct.Caption;

                // defining the new table here, in which only 1 col will be present
                // The column will be primary key, hence no duplicaes will be allowed
                DataTable dt = new DataTable(strNewTable);
                dt.Columns.Add(new DataColumn(strCol, dcolDistinct.DataType, ""));
                dt.PrimaryKey = new DataColumn[]{dt.Columns[0]}; 

                // array to store values, length = 1, since distict runs on 1 col
                Object[] temp = new Object[1];

                Console.WriteLine("host table has {0} rows", dtSource.Rows.Count);
                foreach(DataRow drw in dtSource.Rows)
                {
                        temp[0] = drw[dcolDistinct];
                        dt.LoadDataRow(temp, true);   
                }

                return dt;
        }

        private void test()
        {
                // pass table from which you want to select distinct values - 
OrderDetails here
                // pass column, which you want to make distinct - Product ID
                // the name of the new table

                // the distinct function returns a new datatable containing distinct 
rows of a given column
                DataTable newDT = distinct(dataSet11.Tables["OrderDetails"],
                        dataSet11.Tables["OrderDetails"].Columns["ProductID"], 
"myTable");

                Console.WriteLine("destination table has {0} rows", newDT.Rows.Count);
                foreach(DataRow drw in newDT.Rows)
                {
                        Console.WriteLine(drw[0]);
                }
        }


Paste the above code in your class & call function test(). Change table name/column 
name in above case
Remove Console.writeline, after you feel, it gives you the output

Do post your reply, if this works out for you

HTH
Kalpesh

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to