今天在把DATAREDARE转换成DATATABLE时,出现如题所说的错误。
解决如下:
原代码
foreach (DataRow myRow in schemaTable.Rows)
{
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = myRow.GetType();
myDataColumn.ColumnName = myRow[0].ToString();
datatable.Columns.Add(myDataColumn);
}
更改后代码
foreach (DataRow myRow in schemaTable.Rows)
{
DataColumn myDataColumn = new DataColumn();
myDataColumn.DataType = myRow["DataType"] as Type;
myDataColumn.ColumnName = myRow["ColumnName"] as string;
datatable.Columns.Add(myDataColumn);
}
原因分析中。。。
参考网址:http://topic.csdn.net/u/20081222/16/e9438ec3-b3cb-486d-b8bd-3eb4dba2fc65.html