Usage of DataSet in C
#The DataSet class is one of the core members of ADO.NET and is also used in various development projects based on .Net Platform programming languages are the most commonly used classes when developing database applications. Each DataSet has many DataTables and Relationships. RelationShip should also be a kind of table. The special thing is that this table is only used to connect two data tables. Each DataTable has many datarows and datacols, including ParentRelations, ChildRelations and some restrictions such as the restriction that the primary key cannot be repeated.
Each row of DataSet has a RowState property. It mainly reflects whether the current row has been deleted, updated, or unchanged. There are several options as follows: Deleted, Modified, New, and Unchanged.
Any operation on DataSet is completed in the computer cache.
After the data is extracted from the database, the DataSet is the storage place of the data. It is a cache of data from various data sources mapped in the computer memory, so sometimes the DataSet can be regarded as a data container. .
The DataSet object is a data view that can be expressed in XML form and is a data relationship view.
Recommended tutorial: C# video tutorial
There are generally three ways to use DataSet:
1. Put the database The data in the DataSet is filled in through the DataAdapter object. SqlCommand is actually a Command object. Then fill the DataSet with the retrieved data through the Fill method of the DataAdapter.
2. Operate the DataSet through the DataAdapter object to update the database
DataAdapter updates the database with the data in the DataSet through its Update method. When the data contained in the DataSet instance changes, the Update method is called at this time. The DataAdapter will analyze the changes and execute the corresponding command (INSERT, UPDATE or DELETE), and use this command to update the data in the database.
3. Load XML data stream or text into DataSet
The data in DataSet can be created from XML data stream or document. To load XML data streams and documents into a DataSet, you can use the ReadXml method of the DataSet object.
Data binding is divided into two categories: simple data binding and complex data binding. Components suitable for simple data binding generally include Label, TextBox, etc., and components suitable for complex data binding generally include DataGrid, ListBox, ComboBox, etc.Simple data
Binding generally uses the Add method of the DataBindings property in these components to combine a row in a DataTable in the DataSet with a property of the component. Bind together to achieve the effect of displaying data.
For example: textBox1.DataBindings.Add ( "Text" , dsDataSet1, " Customers. CustomerID ") ;Complexity data binding
Generally, data binding is completed by setting the DataSource property and DisplayMember property of the component. The DataSource attribute value is generally set to the DataSet to be bound, and the DisplayMember attribute value is generally set to the data table or a column in the data table to be bound.
For example:dataGrid1.DataSource = dsDataSet1 ; dataGrid1.DataMember = " Customers " ;
Introduction to Programming Tutorial
, please pay attention to the PHP Chinese website!The above is the detailed content of Usage of DataSet in C#. For more information, please follow other related articles on the PHP Chinese website!