Sunday, November 2, 2008

This row already belongs to another table , C# exception

//Here the scenario

DataSet dsSoruce = new DataSet();
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable("SelectedData");
DataRow[] dr1 = null;
string strExpr = string.Empty;


strExpr = "Name Like 'H%' "
// here we are doing copy into local dataset
ds1 = dsSoruce.Copy();
//copy talbe into local table
dt1 = ds1.Tables[0];
// get selected rows

dr1 = dt1.Select(strExpr);

if ((dr1 != null) && (dr1.Length > 0))
{
//clear the main dataset table
dsSoruce.Tables[0].Clear();
//import the row into main dataset
foreach (DataRow dr in dr1)
{
dsSoruce.ImportRow(dr);
}
}

No comments: