将dataReader转化为DateTable
public static DataTable ConverDateReaderToDataTable(SqlDataReader dataReader)
{
DataTable dataTable = new DataTable();
for (int i = 0; i < dataReader.FieldCount; i++)
{
DataColumn myDateColum = new DataColumn();
myDateColum.DataType = dataReader.GetFieldType(i);
myDateColum.ColumnName = dataReader.GetName(i);
dataTable.Columns.Add(myDateColum);
}
while (dataReader.Read())
{
DataRow myDateRow = dataTable.NewRow();
for (int i = 0; i < dataReader.FieldCount; i++)
{
myDateRow[i] = dataReader[i].ToString();
}
dataTable.Rows.Add(myDateRow);
myDateRow = null;
}
dataReader.Close();
return dataTable;
}
{
DataTable dataTable = new DataTable();
for (int i = 0; i < dataReader.FieldCount; i++)
{
DataColumn myDateColum = new DataColumn();
myDateColum.DataType = dataReader.GetFieldType(i);
myDateColum.ColumnName = dataReader.GetName(i);
dataTable.Columns.Add(myDateColum);
}
while (dataReader.Read())
{
DataRow myDateRow = dataTable.NewRow();
for (int i = 0; i < dataReader.FieldCount; i++)
{
myDateRow[i] = dataReader[i].ToString();
}
dataTable.Rows.Add(myDateRow);
myDateRow = null;
}
dataReader.Close();
return dataTable;
}