閱讀60 返回首頁    go 魔獸


將勾選數據從dataset中篩選出來

方案一:

                DataSet dsTemp = new DataSet();
                dsTemp = dsDt.Clone();
                DataRow[] drs = dsDt.Tables[0].Select("CHECKED='1'");
                foreach (DataRow dr in drs)
                {
                    dsTemp.Tables[0].NewRow();
                    dsTemp.Tables[0].Rows.Add(dr.ItemArray);
                }
                dsDt.AcceptChanges();

小注:

         1、AcceptChanges和RejectChanges:接受或放棄DataSet中所有掛起更改。調用AcceptChanges時,RowState屬性值為Added或Modified的所有行的RowState屬性都將被設置為UnChanged.任何標記為Deleted的DataRow對象將從DataSet中刪除。調用RejectChanges時,任何標記為Added的DataRow對象將會被從DataSet中刪除,其他修改過的DatRow對象將返回前一狀態。

        2、ItemArray:獲取或設置行中所有列的值。

        3、Clone和Copy:使用Copy方法會創建與原DataSet具有相同結構和相同行的新DataSet.使用Clone方法會創建具有相同結構的新DataSet,但不包含任何行。

       4、NewRow() 創建與該表具有相同架構的新DataRow。

方案二:

DataSet dsTemp = new DataSet();
dsTemp.Merge(dsDt.Tables[0].Select("CHECKED='1'"));

小注:

        Merge:從另一個DataSet、DataTable或現有DataSet中的一組DataRow對象載入數據。



最後更新:2017-04-03 12:54:45

  上一篇:go HDU 1230 火星A+B
  下一篇:go 編程之美之斐波那契數列