Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Dataset
Message
From
04/11/2002 10:24:39
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Miscellaneous
Thread ID:
00718356
Message ID:
00718491
Views:
16
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform