Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changes in strongly-typed DataSet .cs files
Message
From
22/03/2005 13:05:54
 
 
To
21/03/2005 14:08:44
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
00980614
Message ID:
00998184
Views:
54
David,

>>Having a typed dataset column property return an object does undo the benefit of a typed data columns,but if that column is nullable and a value type, trying to use the automatically generated property for that column is unsafe and StrongTypingException prone. You can either wrap up property references in try-catch blocks, always check for null using the DataRow indexer before accessing the value, subclass the typed dataset, or change the code in the properties.<

The Typed DataSet contains an IsNull method for each property. So, say you have a property called MyProp. There will be a method called IsMyPropNull(). So, you can either use that to determine if a column contains DBNull, or you can use the DataRow indexer to do it:
// either this:
    MyDataSet.MyTable[0].IsMyPropNull == true
// or this:
    MyDataSet.MyTable[0]["MyProp"] == DBNull.Value
OK, yeah, the programmer might forget that he/she has to do that. Oh well ... they won't forget too many times before it gets drilled into their head (by the rest of us screaming at them <g>).

~~Bonnie
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