Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the use of ADO.Net typed DataSet

Shulou Source: shulou.com Published: 2022-06-03 05:43:10 09月28日 Update

This article mainly introduces the use of ADO.Net typed DataSet, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

First, the disadvantages of weak type DataSet:

1, can only be referenced by the column name, dataset.Tables [0] .Rows [0] ["Age"]. If you write the column name incorrectly, you will not find the error when compiling, so you must keep the column name in mind when developing.

2. Int age=Convert.ToInt32 (dataset.Rows [0] ["Age"]), the value of the field fetched is of type object, so type conversion must be carried out carefully, which is not only troublesome, but also error-prone.

3. Passing the DataSet to other users makes it difficult for the user to identify which columns are available.

4, the runtime can only know all the column names, data binding is troublesome, and can not use the rapid development features of Winform and ASP.Net.

5. Write strongly typed DataSet (typed DataSet,TypedDataSet) yourself, create PersonDataSet classes that inherit from DataSet, and encapsulate int? Properties such as Age and methods such as bool IsAgeNull to populate the PersonDataSet.

2. VS automatically generates strongly typed DataSet:

1. Step: add-> New item-> dataset

2. Drag and drop the table from Server Explorer into DataSet. Note that the drag-and-drop process automatically generates strongly typed DataSet and other classes according to the table structure, without dragging the data over, the program is still connected to the database, and the database connection string is automatically written in App.Config.

3. Use DataSet in the code as an example: CC_RecordTableAdapter adapter=new CC_RecordTableAdapter (); how do I know the class name of Adapter? Select the Adapter,Name attribute in the lower half of the DataSet to be the class name. You need to right-click the class name-> parse

4. Get all the data: adapter.GetData (), example program: traversing and displaying all the data, I

Tags: Data type method database code class name field update common program article question configuration property file error generation midpoint user dialog box Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Redmi macOS NVidia Docker