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("firs tTable");
myTableOne.Colu mns.Add("fCol1" );
for(int i = 0; i<5;i++)
{
DataRow myDr = myTableOne.NewR ow();
myDr[0] = i.ToString();
myTableOne.Rows .Add(myDr);
myDr = null;
}
DataTable myTableTwo = new DataTable("seco ndTable");
myTableTwo.Colu mns.Add("fCol1" );
for(int i=0;i<myTableOn e.Rows.Count;i+ +)
{
DataRow tempRow = myTableTwo.NewR ow();
// 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.c om> wrote in message
news:OQ******** ******@TK2MSFTN GP12.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.ro ws.add(datatabl eTwo.rows(i))"
this statement does not work ..it says
"This row already belongs to another table"
what is the solution please ...