- public static DataTable ConvertDataReaderToDataTable(SqlDataReader dataReader)
- {
-
- DataTable datatable = new DataTable();
-
- try
- {
- for (int i = 0; i < dataReader.FieldCount; i++)
- {
- DataColumn myDataColumn = new DataColumn();
- myDataColumn.DataType = dataReader.GetFieldType(i);
- myDataColumn.ColumnName = dataReader.GetName(i);
- datatable.Columns.Add(myDataColumn);
- }
-
-
- while (dataReader.Read())
- {
- DataRow myDataRow = datatable.NewRow();
- for (int i = 0; i < dataReader.FieldCount; i++)
- {
- myDataRow[i] = dataReader[i].ToString();
- }
- datatable.Rows.Add(myDataRow);
- myDataRow = null;
- }
-
- dataReader.Close();
- return datatable;
- }
- catch (Exception ex)
- {
-
-
- throw new Exception(ex.Message, ex);
- }
- }
posted @
2015-06-28 13:50
大林just
阅读(
1207)
评论()
编辑
收藏
举报