获取DataTable前几条数据

#region 获取DataTable前几条数据 
/// <summary> 
/// 获取DataTable前几条数据 
/// </summary> 
/// <param name="TopItem">前N条数据</param> 
/// <param name="oDT">源DataTable</param> 
/// <returns></returns> 
public static DataTable DtSelectTop(int TopItem, DataTable oDT) 
{ 
    if (oDT.Rows.Count < TopItem) return oDT; 
   
    DataTable NewTable = oDT.Clone(); 
    DataRow[] rows = oDT.Select("1=1"); 
    for (int i = 0; i < TopItem; i++) 
    { 
        NewTable.ImportRow((DataRow)rows[i]); 
    } 
    return NewTable; 
} 
#endregion 

  

posted @ 2017-10-10 09:17  李元伟丶  阅读(3328)  评论(0编辑  收藏  举报