I am trying to copy a row from one table to another in same dataset. code I am using
dsFrom.Tables["asd2"].Rows.Add(dsFrom.Tables["asd"].Rows[0].ItemArray);
I am getting an NullRefferenceException. I've determined that Rows are null, even though there is data in both tables. Can anyone explain why is this happening? Or maybe there is another solution for my problem.
Thanks
This is how I am loading data in them
string query = @"select * from table1;
SqlDataAdapter da = new SqlDataAdapter(query, conn);
DataSet dsFrom = new DataSet();
da.Fill(dsFrom, "asd");
da.Fill(dsFrom, "asd2");
May be you should try to copy rows by this way:
foreach (var row in dsFrom.Tables["asd"].Rows)
{
dsFrom.Tables["asd2"].ImportRow(row);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.