Simple tutorial on using strong Dataset

Source: Internet
Author: User

Disadvantages of weak Dataset:

  • Whenever the retrieved value from dataset is returned as an object, type conversion is required;
  • When used by other developers, they cannot know which columns are available;
  • You can only know the names of all columns at runtime, so it is difficult to bind data.

Therefore, vs provides us with the automatic generation function of a strongly Typed Dataset.


 

 

The following is a simple example.

 

First, create a console project, right-click the project name to add a new project, select a service-based database, and name it test.

 

 

Create a new table named t_person in the database. The table structure is as follows:


 

 

Create a new table for the database and add some data.

 

 

 

 

Add a new dataset item in the project, and drag the t_person table directly from the server resource manager on the left into the design view. Our strong dataset is created!

 

 

Finally, let's see how to use it in the program:

Code

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using test. dataset1tableadapters;

Namespace Test
{
Class Program
{
Static void main (string [] ARGs)
{
T_persontableadapter persontableadapter = new t_persontableadapter ();

// Return a table using the getdata () method
Dataset1.t _ persondatatable table = persontableadapter. getdata ();

Foreach (dataset1.t _ personrow row in table)
{
// Note that data is obtained like an attribute.
Console. writeline (row. Name );
}

Console. readkey ();
}
}
}

 

The running result is as follows:

 

 

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.