开发者

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜