Hi All I'm reading an Access database and some fields have null values. If I use MyReader.GetString() I get a cast error. Also how do I read meno fields? best regards B
You can do your access inside a try/catch, or alternately, just do this: MyReader("MyField").ToString() which I believe will result in an empty string (have not tried it just now...).
::I'm reading an Access database and some fields have null values. If I use ::MyReader.GetString() I get a cast error. Then, simply, do not use GetString (), but GetObject (); And check against null. Do NOT set up a try/catch for this - VERY bad practice, for
performance and code size.
I guess I should have clarified. If the null is an exceptional circumstance, then the try/catch is OK. If a large percentage of the fields are null, then likely explicitly checking for null before casting will be better. I created helper functions to do just
that for me.
Douglas Thanks for that - it works a treat. As he memo field will usually be null this seems to be the better option. Thanks to you all for your replies/help B
BazzaSmith
Member
175 Points
35 Posts
Datareader and Access Null fields and Memos
Nov 27, 2004 05:29 PM|LINK
douglas.reil...
All-Star
23315 Points
4647 Posts
Re: Datareader and Access Null fields and Memos
Nov 27, 2004 06:55 PM|LINK
Programming Microsoft Web Forms
My Blog
thona
Member
20 Points
2923 Posts
Re: Datareader and Access Null fields and Memos
Nov 27, 2004 07:12 PM|LINK
douglas.reil...
All-Star
23315 Points
4647 Posts
Re: Datareader and Access Null fields and Memos
Nov 27, 2004 07:15 PM|LINK
Programming Microsoft Web Forms
My Blog
BazzaSmith
Member
175 Points
35 Posts
Re: Datareader and Access Null fields and Memos
Nov 27, 2004 07:41 PM|LINK