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: