DataTable中數據記錄的排序、檢索、合並、分頁、統計


一、排序

DataView dv=dt.DefaultView;

dv.Sort="id asc,name desc";

dt=dv.ToTable(); 

二、檢索 

DataRow[] matches = dt.Select( " (id<'003') and (name='名字11') and (number like '%2007%') " );

string strName = matches[0]["name"].ToString(); 

三、合並 

假如有2個DataTabel:Dt1,Dt2。表結構一樣將Dt2接在Dt1后可采用方法 

Dt1.Merge(Dt2); 

四、分頁 

PagedDataSource pds =  new  PagedDataSource();
pds.AllowPaging =  true ;
pds.DataSource = dvIntegralExpense;
pds.AllowPaging =  true ;
pds.PageSize = pager.PageSize;
pds.CurrentPageIndex = pager.PageIndex;
rptIntegralExpense.DataSource = pds;
rptIntegralExpense.DataBind();  

五、統計

DataTable實現統計,調用Compute函數,函數原型:

public object Compute(string strExpression,string strFilter) 

參數: 

strExpression:要計算的表達式字符串,基本上類型於Sql Server中的統計表達式

strFilter:統計的過濾字符串,只有滿足這個過濾條件的記錄才會被統計

調用舉例:table.Compute("Count(*)","Sex=0")


資料整理,非原創


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM