Home>Article>Operation and Maintenance> How to analyze DataSet objects and use them

How to analyze DataSet objects and use them

王林
王林 forward
2023-05-16 11:55:06 1021browse
Concept of DataSet object:

DataSet object can be regarded as a (Catch), it can retain the data found from the database, and even temporarily store the entire database

DataSet is the representation of data in memory

The connection between the DataSet object and the data source occurs very briefly. We disconnect from the data source immediately after obtaining the data. We wait until the data is modified or needs to be No connection will be established until the data in the data source is manipulated.

The DataSet object contains a set of DataTable objects and DataRelation objects.

DataTable objects and their use.

The DataTable object is an important object of the DataSet. One, representing a relational data table in memory

Common properties of DataTable objects

TableName: Get or set the name of the table

DataSet: Point out which DataSet the table belongs to

Rows (Add, InsertAt, Remove, RemoveAt): DataRow object collection, which represents the collection of rows of this table

Columns: Data Columns object collection, which represents the collection of columns of this table

Example:

DataSetds = new DataSet();

DataTable student = new DataTable("Student");

DataColumn sno = new DataColumn( "Sno");

sno.DataType = typeof(string);

sno.MaxLength = 8;

DataColumn sname = new DataColumn("Sname");

sno.DataType = typeof(string);

sno.MaxLength = 8;

student.Columns.Add(sno);

student.Columns .Add(sname);

ds.Tables.Add(student);

DataRow drl = student.NewRow();

drl["Sno"] = " 0125";

drl["Sname"] = "Li Shuang";

student.Rows.Add(drl);

DataRow dr2 = student.NewRow();

drl["Sno"] = "0125x";

drl["Sname"] = "xLi Shuang";

student.Rows.Add(dr2);

GridView1.DataSource = ds.Tables[0];

GridView1.DataBind();

The above is the detailed content of How to analyze DataSet objects and use them. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete