Home  >  Article  >  Backend Development  >  Filter selected data from dataset

Filter selected data from dataset

黄舟
黄舟Original
2017-02-25 10:59:152179browse

Option 1:

                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 Notes:

1. AcceptChanges and RejectChanges: Accept or abandon all pending changes in the DataSet. When AcceptChanges is called, the RowState property of all rows whose RowState property value is Added or Modified will be set to UnChanged. Any DataRow objects marked as Deleted will be deleted from the DataSet. When RejectChanges is called, any DataRow objects marked as Added will be deleted from the DataSet, and other modified DatRow objects will be returned to the previous state.

2. ItemArray: Get or set the values ​​of all columns in the row.

3. Clone and Copy: Using the Copy method will create a new DataSet with the same structure and the same rows as the original DataSet. Using the Clone method will create a new DataSet with the same structure. A new DataSet containing no rows.

4. NewRow() Create a new DataRow with the same schema as the table.

Option 2:

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

Small Note:

Merge: Load data from another DataSet, DataTable, or a set of DataRow objects in an existing DataSet.

The above is the content filtered out from the dataset. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn