Results 1 to 8 of 8

Thread: [RESOLVED] Overrides SQLDatareader.item

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Resolved [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

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    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?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Overrides SQLDatareader.item

    So what was your intention? Return Nothing instead of a DBNull or something?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Overrides SQLDatareader.item

    Quote Originally Posted by danasegarane View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Overrides SQLDatareader.item

    Quote Originally Posted by danasegarane View Post
    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width