Close access to ASP. Net (10)

Source: Internet
Author: User

Next, we will discuss how to use DataSet to add, modify, and delete a number in the database.
Data.
First, we need to open a connection. Our database should use the previous section :)
String MyConnString = "Driver = {Microsoft Access Driver (*. mdb )};
DBQ = c:/test. mdb ;";
String strComm = "select * from UserList ";
ADOConnection MyConnection = new ADOConnection (MyConnString );
ADODataSetCommand MyComm = new ADODataSetCommand (strComm, MyConnection );
For the sake of convenience, we only store the content of one table in DataSet:
DataSet MyDataSet = new DataSet ();
MyComm. FillDataSet (MyDataSet, "UserList ");
In this case, a DataSet with UserList table data is obtained. Before explaining DataSet, we still need
To understand the DataSet structure, the following is the DataSet structure tree.
DataSet
RelationsCollection
ExtendedProperties
TablesCollection
DataTables
 
Rows
Columns
Others
Since we are studying DataTable, we don't care about them for the moment. A DataSet contains multiple DataT
A DataTable contains multiple rows, which is the basis for DataSet operations :)
Add data
We can see from the list that adding a Row is actually adding a Row. Here we will also demonstrate
How to add a row of data, we use DataSet as the vertex, huh, if TablesCollection
If RowsCollection goes down, there are some annoying methods called such as dt. AcceptChanges, which are annoying.
You can do it all at once.
DataRow dr = MyDataSet. Tables ["UserList"]. NewRow ();
Dr ["UserName"] = "Zhou Xun ";
Dr ["ReMark"] = "100 ";
Dr ["Comment"] = "Beautiful mm ";
MyDataSet. Tables. Rows. Add (dr );
In the first line, we create a new data row to store the newly added data. Then, in this number
Add the required data to the data row. Dr ["UserName"] indicates that the UserName field is added. You can

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.