Find duplicate record's from datatable add tat record in arraylist

Posted by Jeniffer Shamlin under ASP.NET on 6/12/2012 | Points: 10 | Views : 6121 | Status : [Member] | Replies : 10
Find duplicate record's from datatable and add tat record's in arraylist and then bind tat in gridview...

Thanks & Regards
By
Jeniffer Shamin .S.P



Responses

Posted by: Peermohamedmydeen on: 6/12/2012 [Member] Bronze | Points: 25

Up
0
Down
To find the duplicates and add to array.

IEnumerable<DataRow> uniqueRows = table.AsEnumerable().Distinct(DataRowComparer.Default);


foreach (DataRow uniqueRow in uniqueRows)
{
arrayList.Add(uniqueRow.Column);
}


Note : Not compiled and tested

Thanks
PMM

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 6/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Do You Want duplicate Record Or With Out duplicate Record

Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jeniffer Shamlin on: 6/14/2012 [Member] Starter | Points: 25

Up
0
Down
1. I have stored phone numbers in excel with duplicate values.
2. I stored tat excel in Data table.
3. I bound tat Data table in Grid view.
4. while binding, i have to separate duplicate and original values by for loop and i have to store duplicate record in 1 arraylist tat s arraylist1 and store original value in another arraylist2.
5. and atlast i have to bind arraylist1 in Grid view1 and arraylist2 in Grid view2.

tat's the step's.... pls help me to do this....

Thanks & Regards
By
Jeniffer Shamin .S.P

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 6/14/2012 [Member] Bronze | Points: 25

Up
0
Down
If it is in Sql Easily Possible


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 6/14/2012 [Member] Bronze | Points: 25

Up
0
Down
Follow Two Steps

1) Store Data table To Sql Table
2) Table Should Have one identity column


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jeniffer Shamlin on: 6/14/2012 [Member] Starter | Points: 25

Up
0
Down
no i shld not store in SQL, after i split duplicate and original values only i have to store in SQL


Thanks & Regards
By
Jeniffer Shamin .S.P

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 6/14/2012 [Member] Bronze | Points: 25

Up
0
Down
public DataTable DuplicateRowRemove(DataTable dt, string Col)

{
Hashtable hTable = new Hashtable();
ArrayList ArrDupli = new ArrayList();

foreach (DataRow r in dt.Rows)
{
if (HeshTbl.Contains(r[Col]))
ArrDupli.Add(r);
else
HeshTbl.Add(r[Col], string.Empty);

}

foreach (DataRow R in ArrDupli)
dt.Rows.Remove(R);

return dt;
}


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 6/14/2012 [Member] Bronze | Points: 25

Up
0
Down
using System.Data;

using System.Linq;
...
//assuming 'ds' is your DataSet
//and that ds has only one DataTable, therefore that table's index is '0'
DataTable dt = ds.Tables[0];
DataView dv = new DataView(dt);
string cols = string.Empty;
foreach (DataColumn col in dt.Columns)
{
if (!string.IsNullOrEmpty(cols)) cols += ",";
cols += col.ColumnName;
}
dt = dv.ToTable(true, cols.Split(','));
ds.Tables.RemoveAt(0);
ds.Tables.Add(dt);


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jeniffer Shamlin on: 6/15/2012 [Member] Starter | Points: 25

Up
0
Down
Thank you sir.... i Have 1 doubt, Which coding i shld use?

Thanks & Regards
By
Jeniffer Shamin .S.P

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sabarimahesh on: 6/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Jeniffer Shamlin:

Try Both Code and let mE inform about ur status


Life is a Race
Thanks & Regards
By
Sabari Mahesh P M

Jeniffer Shamlin, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response