/// <summary>
/// 获取指定表中的行对象
/// </summary>
/// <param name="newsList">源数据</param>
/// <param name="start">起始位置从0开始</param>
/// <param name="end">结束位置,如果为0,则读出以下所有的</param>
/// <returns>返回指定位置的数据列表</returns>
public static DataTable SplitTable(DataTable newsList, int start, int end)
{
if (newsList != null)
{
if (start == 1 || start == 0) start = 0;
else start = start - 1;
if (start > newsList.Rows.Count) return newsList;
DataTable dt = newsList.Clone();
for (int i = start; i < newsList.Rows.Count; i++)
{
if (i == end && end != 0) break;
dt.Rows.Add(newsList.Rows[i].ItemArray);
}
return dt;
}
return new DataTable();
}
/// <summary>
/// 将行转换为表
/// </summary>
/// <param name="dt">原始表(需要复制里面的结构)</param>
/// <param name="rows"></param>
/// <returns></returns>
public static DataTable DataRowToTable(DataTable dt, DataRow[] rows)
{
if (dt == null || rows.Length <= 0) return null;
DataTable newsDt = dt.Clone();
foreach (DataRow row in rows)
{
newsDt.ImportRow(row);
}
return newsDt;
}
/// 获取指定表中的行对象
/// </summary>
/// <param name="newsList">源数据</param>
/// <param name="start">起始位置从0开始</param>
/// <param name="end">结束位置,如果为0,则读出以下所有的</param>
/// <returns>返回指定位置的数据列表</returns>
public static DataTable SplitTable(DataTable newsList, int start, int end)
{
if (newsList != null)
{
if (start == 1 || start == 0) start = 0;
else start = start - 1;
if (start > newsList.Rows.Count) return newsList;
DataTable dt = newsList.Clone();
for (int i = start; i < newsList.Rows.Count; i++)
{
if (i == end && end != 0) break;
dt.Rows.Add(newsList.Rows[i].ItemArray);
}
return dt;
}
return new DataTable();
}
/// <summary>
/// 将行转换为表
/// </summary>
/// <param name="dt">原始表(需要复制里面的结构)</param>
/// <param name="rows"></param>
/// <returns></returns>
public static DataTable DataRowToTable(DataTable dt, DataRow[] rows)
{
if (dt == null || rows.Length <= 0) return null;
DataTable newsDt = dt.Clone();
foreach (DataRow row in rows)
{
newsDt.ImportRow(row);
}
return newsDt;
}