Dataset Entry 1

Source: Internet
Author: User

A new member data table is created.

Drag the table to the newly created dataset file to automatically generate the following class

Click to view the properties of the member data tableadapter and you will find that it automatically generates a connection string for us, so you do not need to write it manually. In the past, when ado.net was getting started, the connection string was very big.

In this way, when you use the instance of this class in the program, you can find the benefits of this class.

Using system; using system. collections. generic; using system. LINQ; using system. text; using strongly-Typed Dataset. member Data tableadapters; namespace strong data set {class program {static void main (string [] ARGs) {Member Data tableadapter adapter = new member data tableadapter (); // declare the adapter var DATA = adapter for a database table. getdata (); // get all the databases in this table in the database. foreach (VAR item in data) // traverse each row in this table, data is a datatable object {string output = string. format ("the user name you want to display is: {0}, and the password is: {1}", item. member name, item. password); // The convenience is here. You do not need to remember the fields in this table. The automatically generated class will give you related prompts, smart tip // This is my favorite. net, you can focus on your own processing process, as to how the underlying processing is handed over to the computer to complete the console. writeline (output);} console. readline ();}}}

After the solution is generated, you can see that the program outputs all the usernames and passwords in the member data table:

Or to make it clearer, you can use the For Loop To observe the relationship between the generated class and your table name:

Class program {static void main (string [] ARGs) {Member Data tableadapter adapter = new member data tableadapter (); strong data set. member data. member Data able DATA = adapter. getdata (); For (INT I = 0; I <data. count; I ++) {strong dataset. member data. member Data ROW = data [I]; // you can obtain a string output = string in the database. format ("the user name you want to display is: {0}, and the password is: {1}", row. member name, row. password); // read the required field console from this line. writeline (output);} console. readline ();}}

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.