copy data from one datatable to another - different schemas

M

mcnewsxp

how can i copy data from one datatable to another when the schemas are not the same. i do not need to clone. the table structures are the same, but the data i need to copy over doesn't contain a header row so the first row ends up being the header. so i need to get a header row in there then copythe data over.
tia,
mcnewsxp
 
M

mcnewsxp

DataRow newPlateRow = ds.Tables[0].NewRow();
for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
{
newPlateRow = ds.Tables[0].NewRow();
newPlateRow[0] = dataSet.Tables[0].Rows.ItemArray[0].ToString();
newPlateRow[1] = dataSet.Tables[0].Rows.ItemArray[1].ToString();
ds.Tables[0].Rows.Add(newPlateRow);
}
 
A

Arne Vajhøj

DataRow newPlateRow = ds.Tables[0].NewRow();

You create an object that you do not use.
for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
{
newPlateRow = ds.Tables[0].NewRow();
newPlateRow[0] = dataSet.Tables[0].Rows.ItemArray[0].ToString();
newPlateRow[1] = dataSet.Tables[0].Rows.ItemArray[1].ToString();


Why are you calling ToString()?
ds.Tables[0].Rows.Add(newPlateRow);
}

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top