Home Backend Development C#.Net Tutorial Usage of DataSet in C#

Usage of DataSet in C#

Feb 20, 2020 pm 02:19 PM
c# dataset usage

Usage of DataSet in C#

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

The attribute Tables of DataSet can obtain the number of tables in the DATASET: DataSet.Tables.Count

The Tables of DataSet is a Table array, specify the A table: DataSet.Tables[i];//i is the position of

Table in the array sequence or DataSet.Tables["table name"];

through the Rows object group of Table Count gets the number of records in the table: DataSet.Tables[i].Rows.Count;

Gets the number of columns: DataSet.Tables[i].Columns.Count;

More

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Active Directory with C# Active Directory with C# Sep 03, 2024 pm 03:33 PM

Guide to Active Directory with C#. Here we discuss the introduction and how Active Directory works in C# along with the syntax and example.

C# Serialization C# Serialization Sep 03, 2024 pm 03:30 PM

Guide to C# Serialization. Here we discuss the introduction, steps of C# serialization object, working, and example respectively.

Random Number Generator in C# Random Number Generator in C# Sep 03, 2024 pm 03:34 PM

Guide to Random Number Generator in C#. Here we discuss how Random Number Generator work, concept of pseudo-random and secure numbers.

C# Data Grid View C# Data Grid View Sep 03, 2024 pm 03:32 PM

Guide to C# Data Grid View. Here we discuss the examples of how a data grid view can be loaded and exported from the SQL database or an excel file.

Factorial in C# Factorial in C# Sep 03, 2024 pm 03:34 PM

Guide to Factorial in C#. Here we discuss the introduction to factorial in c# along with different examples and code implementation.

Patterns in C# Patterns in C# Sep 03, 2024 pm 03:33 PM

Guide to Patterns in C#. Here we discuss the introduction and top 3 types of Patterns in C# along with its examples and code implementation.

Prime Numbers in C# Prime Numbers in C# Sep 03, 2024 pm 03:35 PM

Guide to Prime Numbers in C#. Here we discuss the introduction and examples of prime numbers in c# along with code implementation.

The difference between multithreading and asynchronous c# The difference between multithreading and asynchronous c# Apr 03, 2025 pm 02:57 PM

The difference between multithreading and asynchronous is that multithreading executes multiple threads at the same time, while asynchronously performs operations without blocking the current thread. Multithreading is used for compute-intensive tasks, while asynchronously is used for user interaction. The advantage of multi-threading is to improve computing performance, while the advantage of asynchronous is to not block UI threads. Choosing multithreading or asynchronous depends on the nature of the task: Computation-intensive tasks use multithreading, tasks that interact with external resources and need to keep UI responsiveness use asynchronous.

See all articles