DataSet object

DataSet

It is a database that exists in memory

Its data comes from the data of the database server

DataSet是ADO.NET的中心概念。可以把DataSet当成内存中的数据库,DataSet是不依赖于数据库的独立数据集合。
创建DataSet对象
引入命名空间 System.Data
实例化: DataSet ds =new DataSet( );
属性和方法

Attributes

用DataAdapter可对来自数据源的记录进行操作。通过使用4个DataAdapter属性(指定执行某条SQL语句或调用某个存储过程)中的一个,可以指定所要执行的操作。这些属性实际上是SqlCommand或OleDbCommand类的实例对象:
        SelectCommand引用从数据源中检索行的Command对象。

InsertCommand引用将插入的行从DataSet写入数据源的Command对象。

UpdateCommand引用将修改的行从DataSet写入数据源的Command对象。

DeleteCommand引用从数据源中删除行的Command对象。

method

使用DataAdapter提供的方法,可以填充DataSet或将DataSet表中的更改传送到相应的数据存储区。

Fill。使用SqlDataAdapter(或OleDbDataAdapter)的这个方法,从数据源增加或刷新行,并将这些行放到DataSet表中。Fill方法调用SelectCommand属性所指定的SELECT语句。
    Update。使用DataAdapter对象的这个方法,将DataSet表的更改传送到相应的数据源中。该方法为DataSet的DataTable中每一指定的行调用相应的INSERT、UPDATE或DELETE命令。

DataAdapter Data Adapter

DataAdapter表示一组 SQL 命令和一个数据库连接,它们用于填充 DataSet和更新数据源。

DataAdapter对象充当DataSet和数据源之间用于检索和保存数据的桥梁。DataAdapter类代表用于填充DataSet以及更新数据源的一组数据库命令和一个数据库连接。DataAdapter对象是ADO.NET数据提供程序的组成部分,该数据提供程序还包括连接对象、数据读取器对象和命令对象。
导入命名空间

System.Data.SqlClient;

Instantiate

DataAdapter da =new DataAdapter ( 常用sql语句,数据连接(连接对象));

fill method

语法:DataAdapter 对象.fill (DataSet对象,数据表名称 )

Steps

Steps to use the DataSet with SQL Server .NET data provider
(1) Create a SqlConnection object and connect to the SQL Server database.
(2) Create a SqlDataAdapter object. This object contains properties that can point to four SqlCommand objects. These objects specify SQL statements to perform data operations such as SELECT, INSERT, DELETE, and UPDATE in the database.
(3) Create a DataSet object that contains one or more tables.
(4) Use the SqlDataAdapter object to fill the DataSet table by calling the Fill method. SqlDataAdapter implicitly executes the SqlCommand object containing the SELECT statement.
(5) Modify the data in the DataSet. You can perform the modification programmatically, or bind the DataSet to a user interface control (such as the DataGrid), and then change the data in the control.
(6) When preparing to return data changes to the database, you can use the SqlDataAdapter and call the Update method. The SqlDataAdapter object implicitly uses its SqlCommand object to execute INSERT, DELETE, and UPDATE statements on the database.
Import data into ComboBox control
ComboBox drop-down list

DataSource 数据源
ValueMember 实际值
DisplayMember 显示的值

Example

comboBox1.DataSource = ds.Tables[“啊”];
comboBox1.DisplayMember = “nickname”;

Guess you like

Origin blog.csdn.net/qq_50722361/article/details/110790721