using System.Data; namespace learun.database { /// /// 版 本 EasyCode EC管理后台 /// Copyright (c) 2019-present EC管理有限公司 /// 创建人:tobin /// 日 期:2019.09.05 /// 描 述:db通用帮助类 /// public class DBCommonHelper { /// /// 将IDataReader转换为DataTable /// /// datatable /// IDataReader public static DataTable IDataReaderToDataTable(IDataReader reader) { using (reader) { DataTable objDataTable = new DataTable("Table"); int intFieldCount = reader.FieldCount; for (int intCounter = 0; intCounter < intFieldCount; ++intCounter) { objDataTable.Columns.Add(reader.GetName(intCounter).ToLower(), reader.GetFieldType(intCounter)); } objDataTable.BeginLoadData(); object[] objValues = new object[intFieldCount]; while (reader.Read()) { reader.GetValues(objValues); objDataTable.LoadDataRow(objValues, true); } reader.Close(); reader.Dispose(); objDataTable.EndLoadData(); return objDataTable; } } } }