|
-
Apr 7th, 2009, 01:16 AM
#1
[RESOLVED] Overrides SQLDatareader.item
Hi All,
This means article says that SQLDatareader.item is Overidable. I tried to to create a custom class which inhherits the SQLDataReader, and came with the error that this class cannot be inherited.. Is any other way ?
Please mark you thread resolved using the Thread Tools as shown
-
Apr 7th, 2009, 01:28 AM
#2
Re: Overrides SQLDatareader.item
The reason that that property is overridable is that it is inherited from the DbDataReader class. DbDataReader is the base class for all data readers and it defines that property, then each specific data reader class is supposed to override it. A member that's declared Overridable in a base class must be Overridable in any derived classes too.
The SqlDataReader class is not supposed to be inherited though. What would be the point of inheriting it? The only way you can create an instance is by calling ExecuteReader on a SqlCommand, so how would you ever instantiate your derived class?
-
Apr 7th, 2009, 01:32 AM
#3
Re: Overrides SQLDatareader.item
Thanks for the Reply Jhon. The Problem is that I am working on project where they have used the SQLDatareader.item("") to get the value after executing the SQLDatareader.ExecuteReader method. They have not handled the null values from SQLData. I tried to start implementing checking for ISDBNull for each SQLDatareader.item("") of this line.
Instead of doing that i was looking for common method to implement for handling the Null values, So that If I declare the SQLDatareader in the Page Level and not in Function/Sub Level
Please mark you thread resolved using the Thread Tools as shown
-
Apr 7th, 2009, 01:36 AM
#4
Re: Overrides SQLDatareader.item
So what was your intention? Return Nothing instead of a DBNull or something?
-
Apr 7th, 2009, 01:37 AM
#5
Re: Overrides SQLDatareader.item
I need to return an Empty string if it is an DBNULL
Please mark you thread resolved using the Thread Tools as shown
-
Apr 7th, 2009, 01:42 AM
#6
Re: Overrides SQLDatareader.item
 Originally Posted by danasegarane
I need to return an Empty string if it is an DBNULL
Then you don't really need to check for null's. Just tack a ToString call onto the Item property. DBNull.ToString returns an empty string while String.ToString returns the String itself, so it works in all cases. Obviously this is only for String columns.
Last edited by jmcilhinney; Apr 7th, 2009 at 01:46 AM.
-
Apr 7th, 2009, 01:56 AM
#7
Re: Overrides SQLDatareader.item
Thanks John.. I miss read that .Tostring Will throw an Exception for DBNull.. Now tested with a Small Application working good..
Thanks once again...
Please mark you thread resolved using the Thread Tools as shown
-
Apr 7th, 2009, 01:59 AM
#8
Re: Overrides SQLDatareader.item
 Originally Posted by danasegarane
Thanks John.. I miss read that .Tostring Will throw an Exception for DBNull.
Yeah, it would throw an exception for a null reference but database null's are not null references. They are instances of the DBNull class, which is easy to forget.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|