asp.net we continue in front of the content, hehe, this time is mainly about the powerful function of the dataset:). The last time we blew up.
Bubbles (The meaning of the words do not count, Hunan people can understand it:), this time must not break the promise:)
Storing multiple data tables in a dataset
Many of us in the ASP are accustomed to using the Recordset object to manipulate the database, but the recordset has a missing
The point is that a recordset can only store one datasheet, and when we need to manipulate multiple tables, we have to work on multiple re
Back and forth in the Cordset, although these are not used after the habit, but for a novice, this is
A very troublesome thing to do. Just those variable names can muddy you, now well, in the ASP.net, only need
A dataset can handle everything. greatly facilitates our program. We still look the same.
Preface, and then to explain carefully.
Open a Join
ADOConnection myconnection = new ADOConnection (myConnString);
Open two DataSetCommand
Adodatasetcommand MyComm1 = new Adodatasetcommand (strcomm1,myconnection);
Adodatasetcommand MyComm2 = new Adodatasetcommand (strcomm2,myconnection);
DataSet myDataSet = new DataSet ();
Save a userlist,booklist table in a dataset
Mycomm1.filldataset (myDataSet, "userlist");
Mycomm2.filldataset (myDataSet, "Booklist");
In the example above, we opened an Access database named Test.mdb, and then put two of his
The table "UserList" and "Booklist" are displayed using two DataGrid controls. The pictures shown are as follows:
ADOConnection myconnection = new ADOConnection (myConnString);
Adodatasetcommand MyComm1 = new Adodatasetcommand (strcomm1,myconnection);
Adodatasetcommand MyComm2 = new Adodatasetcommand (strcomm2,myconnection);
These are just doing some preparation work, opening a connection, and opening two datasetcommand to get two
Table's data.
DataSet myDataSet = new DataSet ();
This is the key to our program, where we open the DataSet object we want to manipulate. Below we will need to put the number
The contents of the table have been filled in the dataset.
Here is our main content today. The previous chapters have said that you can contain multiple data in a dataset
, here we have two database tables in this dataset called myDataSet, but if we want to,
We can also insert XML data inside, and they don't conflict. We can rest assured that the use of hehe
。
The following code is to transfer the myDataSet data to the DataGrid control display. There's not much to say here.
Here we simply say that the dataset can hold multiple data tables function, we look like there is nothing
In particular. It does not seem to have any special features here, but if you match the dataset with the modifications, add
Add, delete function, we operate the database becomes very simple. We can read the database into the dataset first and then
Modify the data in the dataset, if not satisfied with the change, we can also use the RejectChanges method to comprehensively
Restore, and finally to the database to update.
In the next section, we'll explain how to use a dataset to add, modify, and delete data.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service