-
将DataReader转换为DataTable
- 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);
- }
- }
-
相关阅读:
常用性能测试工具和命令汇总
delphi try except语句 和 try finally语句用法以及区别
delphi中 ExecSQL 与 open
Javascript闭包
遍历一个List的几种方法
IDEA导入项目jar包红线、依赖问题....
HashMap、Hashtable、ConcurrentHashMap的原理与区别
记一次CPU飙升BUG
创建单链表
【剑指offer】题目二
-
原文地址:https://www.cnblogs.com/just09161018/p/4605457.html
Copyright © 2020-2023
润新知