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.
52 lines
1.6 KiB
52 lines
1.6 KiB
using System.Data.Common;
|
|
|
|
namespace Znyc.Cloudcar.Admin.Commons.Data
|
|
{
|
|
public class MicroDataTableHelper
|
|
{
|
|
/// <summary>
|
|
/// DbDataReaders 数据转化Datatable
|
|
/// </summary>
|
|
/// <param name="reader"></param>
|
|
/// <param name="pageIndex"></param>
|
|
/// <param name="pageSize"></param>
|
|
/// <returns></returns>
|
|
public static MicroDataTable FillDataTable(DbDataReader reader, int pageIndex, int pageSize)
|
|
{
|
|
bool defined = false;
|
|
MicroDataTable table = new MicroDataTable();
|
|
int index = 0;
|
|
int beginIndex = pageSize * pageIndex;
|
|
int endIndex = pageSize * (pageIndex + 1) - 1;
|
|
while (reader.Read())
|
|
{
|
|
object[] values = new object[reader.FieldCount];
|
|
if (!defined)
|
|
{
|
|
for (int i = 0; i < reader.FieldCount; i++)
|
|
{
|
|
MicroDataColumn column = new MicroDataColumn
|
|
{
|
|
ColumnName = reader.GetName(i),
|
|
ColumnType = reader.GetFieldType(i)
|
|
};
|
|
table.Columns.Add(column);
|
|
}
|
|
|
|
defined = true;
|
|
}
|
|
|
|
if (index >= beginIndex && index <= endIndex)
|
|
{
|
|
reader.GetValues(values);
|
|
table.Rows.Add(new MicroDataRow(table.Columns, values));
|
|
}
|
|
|
|
index++;
|
|
}
|
|
|
|
table.TotalCount = index;
|
|
return table;
|
|
}
|
|
}
|
|
}
|