当前位置:Gxlcms >
数据库问题 >
convert SqlDataReader to DataTable
convert SqlDataReader to DataTable
时间:2021-07-01 10:21:17
帮助过:6人阅读
static DataTable ConvertDataReaderToDataTable(SqlDataReader reader)
{
try
{
DataTable objDataTable =
new DataTable();
int intFieldCount =
reader.FieldCount;
for (
int intCounter =
0; intCounter < intFieldCount; ++
intCounter)
{
objDataTable.Columns.Add(reader.GetName(intCounter), reader.GetFieldType(intCounter));
}
objDataTable.BeginLoadData();
object[] objValues =
new object[intFieldCount];
while (reader.Read())
{
reader.GetValues(objValues);
objDataTable.LoadDataRow(objValues, true);
}
reader.Close();
objDataTable.EndLoadData();
return objDataTable;
}
catch (Exception ex)
{
throw new Exception(
"Convert Error!", ex);
}
}
convert SqlDataReader to DataTable
标签:row object err stat tab ble pre nload span