Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Dataset
Message
De
04/11/2002 10:24:39
 
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Titre:
Divers
Thread ID:
00718356
Message ID:
00718491
Vues:
17
We take it one step further and sub-class the generated class. That way we can add additional functionality to a DataSet. For example, we have an additional method that we add to each dataset class, called FillWithXML() that easily allows us to fill the DataSet from an XML string instead of from the SQL Server backend (useful for cached files).

~~Bonnie

>>What are the advantages of creating a dataset as a class?
>
>When you build a dataset with the designer, the generated class allows you to use strong typing and intellisense.
>
>Consider the following code (with custom DS class)
>
>MyDS ds = new MyDS();  // my custom class
>...
>foreach (MyDS.OrdersRow row in ds.Orders.Rows) {
>    row.CustomerID = cusID;
>    row.OrderState = 1; // 1=Pending
>    }
>
>with this one (generic DataSet)
>
>DataSet ds = new DataSet();
>...
>foreach (DataRow row in ds.Tables["Orders"].Rows) {
>    row["CustomerId"] = cusID; // undetected error here! field name
>is "CustomerID"
>    row["OrderType"] = "Pending";    // wrong type
>    }
>
>Not only the first option is easier to type (intellisense avoids the need to remember each table/column name) but it's also safer: the compiler will check the existence and type of each member.
>
>Regards,
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform