Intimate contact asp.net (10)

Source: Internet
Author: User
In the next section, our section focuses on how to use datasets to add, modify, and delete a number in the database
According
First we need to open a connection, our database is still in the previous section of the bar:
String myConnString = "Driver={microsoft Access Driver (*.mdb)};
Dbq=c:/test/test.mdb; ";
String Strcomm = "SELECT * from UserList";
ADOConnection myconnection = new ADOConnection (myConnString);
Adodatasetcommand Mycomm = new Adodatasetcommand (strcomm,myconnection);
Here we are in order to explain conveniently, only in the dataset into a table content:
DataSet myDataSet = new DataSet ();
Mycomm.filldataset (myDataSet, "userlist");
At this point we get a DataSet with UserList table data. Before we explain the dataset, we need
To understand the structure of the dataset, below is the structure tree of the dataset
DataSet
Relationscollection
ExtendedProperties
Tablescollection
DataTables
 
Rows
Columns
Other
Because we're studying the DataTable, the rest of us don't care about them for a while. A dataset contains multiple Datat
Able, a DataTable contains multiple row, which is the basis of our operation DataSet:
Add data
Add a data, from the above list we can see, is actually add row row, here we also demonstrate
How to add a row of data, we program everything to the dataset as the apex, hehe, if tablescollection
, rowscollection down, there are some annoying dt. AcceptChanges the invocation of these methods is annoying
, it's time to take care of it.
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 row of data that stores our newly added data. And then we're in this number
According to the line, add the data we need. dr["UserName"] indicates that the UserName field is added and you can
Related Article

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.