- Joined
- May 4, 2009
- Messages
- 1
- Reaction score
- 0
Hi All...
This is phani... i need a help from u... i am using a datatable i need to found the duplicate rows based on first column and removing those dup rows by appending the corresponding column values to the original row....
i am using the following code to remove the duplicate rows... but i have a pbm while appending these values to the original row....
Please help me out if u know any solution...........................
try
{
foreach (DataRow drow in temp.Rows)
{
if (hTable.Contains(drow["Name"]))
{
duplicateList.Add(drow);
int index = 0;
if (original.Contains(drow["Name"]))
{
index = Array.IndexOf(original.ToArray(), drow["Name"]);
}
for (int c = 1; c < temp.Columns.Count; c++)
{
if (drow[c].ToString() != "" && temp.Rows[index][c].ToString() == "")
{
temp.Rows[index][c] = temp.Rows[index][c] + drow[c].ToString();
//orig.Rows[index][c] = temp.Rows[index][c] + drow[c].ToString();
}
else if (drow[c].ToString() != "" && temp.Rows[index][c].ToString() != "")
{
temp.Rows[index][c] = temp.Rows[index][c] + "," + drow[c].ToString();
}
}
}
else
{
hTable.Add(drow["Name"], string.Empty);
original.Add(drow["Name"]);
}
}
//
try
{
foreach (DataRow dRow in duplicateList)
temp.Rows.Remove(dRow);
}
catch
{
}
}
catch
{
}
// ******************** ending
GridView1.DataSource =temp;
GridView1.DataBind();
This is phani... i need a help from u... i am using a datatable i need to found the duplicate rows based on first column and removing those dup rows by appending the corresponding column values to the original row....
i am using the following code to remove the duplicate rows... but i have a pbm while appending these values to the original row....
Please help me out if u know any solution...........................
try
{
foreach (DataRow drow in temp.Rows)
{
if (hTable.Contains(drow["Name"]))
{
duplicateList.Add(drow);
int index = 0;
if (original.Contains(drow["Name"]))
{
index = Array.IndexOf(original.ToArray(), drow["Name"]);
}
for (int c = 1; c < temp.Columns.Count; c++)
{
if (drow[c].ToString() != "" && temp.Rows[index][c].ToString() == "")
{
temp.Rows[index][c] = temp.Rows[index][c] + drow[c].ToString();
//orig.Rows[index][c] = temp.Rows[index][c] + drow[c].ToString();
}
else if (drow[c].ToString() != "" && temp.Rows[index][c].ToString() != "")
{
temp.Rows[index][c] = temp.Rows[index][c] + "," + drow[c].ToString();
}
}
}
else
{
hTable.Add(drow["Name"], string.Empty);
original.Add(drow["Name"]);
}
}
//
try
{
foreach (DataRow dRow in duplicateList)
temp.Rows.Remove(dRow);
}
catch
{
}
}
catch
{
}
// ******************** ending
GridView1.DataSource =temp;
GridView1.DataBind();