Home > Backend Development > C#.Net Tutorial > Filter selected data from dataset

Filter selected data from dataset

黄舟
Release: 2017-02-25 10:59:15
Original
2200 people have browsed it

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();
Copy after login

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'"));
Copy after login

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)!


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template