You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.1 KiB
43 lines
1.1 KiB
using System.Data;
|
|
|
|
namespace learun.database
|
|
{
|
|
/// <summary>
|
|
/// 版 本 EasyCode EC管理后台
|
|
/// Copyright (c) 2019-present EC管理有限公司
|
|
/// 创建人:tobin
|
|
/// 日 期:2019.09.05
|
|
/// 描 述:db通用帮助类
|
|
/// </summary>
|
|
public class DBCommonHelper
|
|
{
|
|
/// <summary>
|
|
/// 将IDataReader转换为DataTable
|
|
/// </summary>
|
|
/// <returns>datatable</returns>
|
|
/// <param name="reader">IDataReader</param>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|