Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Changes in strongly-typed DataSet .cs files
Message
De
22/03/2005 13:05:54
 
 
À
21/03/2005 14:08:44
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 1.1
Database:
MS SQL Server
Divers
Thread ID:
00980614
Message ID:
00998184
Vues:
50
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform