Check out the screening data from the dataset

Option One:

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();

Small note:

         1, AcceptChanges and RejectChanges: acceptance or rejection of the DataSet all pending changes. When you call AcceptChanges, RowState property value is Added or Modified RowState attributes of all the rows will be set to UnChanged. Anything labeled Deleted from the DataSet DataRow object is deleted. When you call RejectChanges, any mark will be deleted as DataRow objects Added from the DataSet, other modified DatRow object will return to the previous state.

        2, ItemArray: obtaining values ​​for all columns or rows are provided.

        3, Clone and Copy: use the Copy method creates a new DataSet with the original DataSet has the same structure and the same line use. Clone method creates a new DataSet with the same structure, but does not contain any rows.

       4, NewRow () Creates a new DataRow with the same schema of the table.

Option II:

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

Small note:

        Merge: DataSet from another, or a group of existing DataSet DataTable DataRow object of load data.



Reproduced in: https: //my.oschina.net/cjkall/blog/195858

Guess you like

Origin blog.csdn.net/weixin_34090562/article/details/91756390