webForumDet fria alternativet

Dataset

5 svar · 286 visningar · startad av Dino

DinoMedlem sedan sep. 20011 914 inlägg
#1

Vad är skillnaden på typed och untyped DataSets. Förklara utförligt, tack.

NETworkMedlem sedan juni 20011 732 inlägg
#2

Saxat från dokumentationen:

*Datasets can be typed or untyped. A typed dataset is a dataset that is first derived from the base DataSet class and then uses information in an XML Schema file (an .xsd file) to generate a new class. Information from the schema (tables, columns, and so on) is generated and compiled into this new dataset class as a set of first-class objects and properties.

Because a typed DataSet class inherits from the base DataSet class, the typed class assumes all of the functionality of the DataSet class and can be used with methods that take an instance of a DataSet class as a parameter

An untyped dataset, in contrast, has no corresponding built-in schema. As in a typed dataset, an untyped dataset contains tables, columns, and so on — but those are exposed only as collections. (However, after manually creating the tables and other data elements in an untyped dataset, you can export the dataset's structure as a schema using the dataset's WriteXmlSchema method.)

You can use either type of dataset in your applications. However, Visual Studio has more tool support for typed datasets, and they make programming with the dataset easier and less error-prone.*

DinoMedlem sedan sep. 20011 914 inlägg
#3

Ok, och vad är att föredra. Fördelar, nackdelar.

NETworkMedlem sedan juni 20011 732 inlägg
#4

Exempel, om du har ett typed dataset kan du referera till en kolumn så här:

string s;
s = dsCustomersOrders1.Customers[0].CustomerID;

...men om du har ett untyped dataset måste du skriva så här:

string s = (string)dsCustomersOrders1.Tables["Customers"].Rows[0]["CustomerID"];

Typed datasets är alltså både lättare att läsa och har bättre support i vs.net, enklare kod, mindre risk för fel och strul. Men självklart finns det tillfällen då untyped är att föredra (annars skulle den ju inte finnas antar jag).

NETworkMedlem sedan juni 20011 732 inlägg
#5

Lite mer saxat från dokumentationen:

Even though typed datasets have many advantages, there are a variety of circumstances under which an untyped dataset is useful. The most obvious scenario is that no schema is available for the dataset. This might occur, for example, if your application is interacting with a component that returns a dataset, but you do not know in advance what its structure is. Similarly, there are times when you are working with data that does not have a static, predictable structure; in that case, it is impractical to use a typed dataset, because you would have to regenerate the typed dataset class with each change in the data structure.

DinoMedlem sedan sep. 20011 914 inlägg
#6

Ok, tack. Håller på att läsa en artikel och behövde reda ut begreppen.

130 ms totalt · 3 externa anrop · v20260731065814-full.2b84b982
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
127 ms — hämta tråd, inlägg och bilagor (db)