Datatable複製
僅格式:DataTable dt = DatasoruceDT.Clone();
格式與資料:DataTable dt = DatasoruceDT.Copy();
Datatable搜尋
方法一、
var drList =DatasoruceDT.Select("abc='" + item.abc+ "' and QTY=" + item.Qty + ");
如果是字串型態,則要加單引號;如是數字型態,則不需要加單引號
方法二、
//1.設定多個主鍵
DatasoruceDT.PrimaryKey = new DataColumn[] { DatasoruceDT.Columns["abc"],
DatasoruceDT.Columns["QTY"]};
//2.欲查詢的資料集
object[] searchObj = new object[] { "Data",50};
//3.搜尋DataRow 與傳入的List比對出所要的資料
DataRow dr = DatasoruceDT.Rows.Find(searchObj );
參考資料:
http://msdn.microsoft.com/zh-tw/library/system.data.datatable.select.aspx
http://www.dotblogs.com.tw/yc421206/archive/2009/10/20/11152.aspx
http://souts.pixnet.net/blog/post/9132068-ado.net%E4%B8%ADdataset%E3%80%81datatable%E3%80%81datarow%E8%A4%87%E8%A3%BD%E6%96%B9%E5%BC%8F
http://kkxl.iteye.com/blog/866318