Hi,
i am not sure if we can add a row which is a part of another table. I have
written a sample to explain how to do that.
DataTable myTableOne = new DataTable("firstTable");
myTableOne.Columns.Add("fCol1");
for(int i = 0; i<5;i++)
{
DataRow myDr = myTableOne.NewRow();
myDr[0] = i.ToString();
myTableOne.Rows.Add(myDr);
myDr = null;
}
DataTable myTableTwo = new DataTable("secondTable");
myTableTwo.Columns.Add("fCol1");
for(int i=0;i<myTableOne.Rows.Count;i++)
{
DataRow tempRow = myTableTwo.NewRow();
// you can loop here for each columns in the tableone if
you have more columns
tempRow[0] = myTableOne.Rows[i][0];
// tempRow = myTableOne.Rows[i];
// Remember will not work here as its the refrence
// of the row from tableone which is assigned to the
temprow so temprow will be pointing to
// the row of tabletwo
myTableTwo.Rows.Add(tempRow);
tempRow = null;
}
HTH
Regards
Ashish M Bhonkiya
"ypul" <yp**@hotmail.com> wrote in message
news:OQ**************@TK2MSFTNGP12.phx.gbl...
can anyone tell me please ..
how to copy one datarow from one datatable to another..
I want to extract some specific rows from one datatable and put into
antoher ...
" datatableOne.rows.add(datatableTwo.rows(i))"
this statement does not work ..it says
"This row already belongs to another table"
what is the solution please ...