hi
Assume we created strongly typed DataSet which consists of two tables - Categories and Products.
Anyways, typed DataSets enable strong type checking. What follows are examples I’m aware of where strong type checking is applied:
a)
Instead of performing string-based collection lookup, where entering the wrong name of a table or a field causes runtime exception:
Label1.Text = (string)dataset.Tables[“Categories”].Rows[0][“CategoryName”];
, you can instead use strongly typed property, where specifying wrong field or table name is detected at compile time :
Label1.Text = dataset.Categories[0].CategoryName;
b)
With ordinary DataSets, assigning a value of incompatible type to a particular field ( which is contained inside DataRow object ) causes runtime exception. With strongly typed DataSets, incompatible assignments are detected at compile time
c)
With regular DataSets, adding DataRow instance to table that uses different schema, causes an exception to be thrown:
*DataTable.Rows.Add(some_DataRow);*
But AddCategoriesRow(CategoriesRow row) enables incompatible DataRow instances to be detected at compile time
To my questions:
1) assuming we pass to DataTable.Rows.Add(); as an argument a DataRow instance with different schema than the one this table uses, when exactly will runtime notice this? First time our code tries to access that row or …?
2) Are there any other situations where strongly typed DataSets provides type safety, but regular DataSets don’t?
thank you