how to load datatable from datarow array?
DataTable dt = new DataTable();
DataRow[] dr = (DataTable)dsData.Tables[0].Select("Some Criteria");
dt = (DataTable)dsData.Tables[0].clone();
dt.Rows.Add(dr); //line causing the error
The above code is throwing an error in bolded line as follows
"Unable to cast o开发者_StackOverflowbject of type 'System.Data.DataRow' to type
'System.IConvertible'.Couldn't store in pipelinesubstatusid Column.
Expected type is Decimal."
can you help me to overcome the problem
try this:
foreach(var row in dr)
{
var r=dt.NewRow();
r.ItemArray = row.ItemArray;
dt.Rows.Add(r);
}
or
foreach(var row in dr)
{
dt.Rows.Add(row);
}
精彩评论