DBNull problems - typed datasets - webservices

Discussion in 'ASP .Net Web Services' started by JezB, Jan 12, 2004.

  1. JezB

    JezB Guest

    I'm using a typed dataset to get rows from a database, but getting an
    invalid cast exception when trying to examine columns in that row which are
    null in the database. This is because of some code generated within the
    typed dataset's class (eg. myDataSet.cs) :-

    catch (InvalidCastException e) {
    throw new StrongTypingException("Cannot get value because it is
    DBNull.", e);
    }

    I know I can force a change of this code by setting a NullValue property of
    the specific elements within my dataset. However, when I expose the dataset
    schema through a web service (it's exposed by having an exposed method
    return a dataset of this type), this change seems to be ignored. It seems to
    regenerate the default code in a class file called Reference.cs - and I must
    admit I'm not quite sure what's going on here.

    Could anyone explain this ? and what can I do to resolve this issue ?
    JezB, Jan 12, 2004
    #1
    1. Advertising

  2. JezB

    Miha Markic Guest

    Hi JezB,

    For every property (field) that can be null there is a Is*fieldname*Null()
    method in typed dataset.

    --
    Miha Markic - RightHand .NET consulting & software development
    miha at rthand com
    www.rthand.com

    "JezB" <> wrote in message
    news:...
    > I'm using a typed dataset to get rows from a database, but getting an
    > invalid cast exception when trying to examine columns in that row which

    are
    > null in the database. This is because of some code generated within the
    > typed dataset's class (eg. myDataSet.cs) :-
    >
    > catch (InvalidCastException e) {
    > throw new StrongTypingException("Cannot get value because it is
    > DBNull.", e);
    > }
    >
    > I know I can force a change of this code by setting a NullValue property

    of
    > the specific elements within my dataset. However, when I expose the

    dataset
    > schema through a web service (it's exposed by having an exposed method
    > return a dataset of this type), this change seems to be ignored. It seems

    to
    > regenerate the default code in a class file called Reference.cs - and I

    must
    > admit I'm not quite sure what's going on here.
    >
    > Could anyone explain this ? and what can I do to resolve this issue ?
    >
    >
    Miha Markic, Jan 12, 2004
    #2
    1. Advertising

  3. JezB

    JezB Guest

    You're right !! How did I miss this ?
    Thanks.

    However, I'd still like to know why exposing a dataset as a webservice
    changes the generated code.

    "Miha Markic" <miha at rthand com> wrote in message
    news:...
    > Hi JezB,
    >
    > For every property (field) that can be null there is a Is*fieldname*Null()
    > method in typed dataset.
    >
    > --
    > Miha Markic - RightHand .NET consulting & software development
    > miha at rthand com
    > www.rthand.com
    >
    > "JezB" <> wrote in message
    > news:...
    > > I'm using a typed dataset to get rows from a database, but getting an
    > > invalid cast exception when trying to examine columns in that row which

    > are
    > > null in the database. This is because of some code generated within the
    > > typed dataset's class (eg. myDataSet.cs) :-
    > >
    > > catch (InvalidCastException e) {
    > > throw new StrongTypingException("Cannot get value because it is
    > > DBNull.", e);
    > > }
    > >
    > > I know I can force a change of this code by setting a NullValue property

    > of
    > > the specific elements within my dataset. However, when I expose the

    > dataset
    > > schema through a web service (it's exposed by having an exposed method
    > > return a dataset of this type), this change seems to be ignored. It

    seems
    > to
    > > regenerate the default code in a class file called Reference.cs - and I

    > must
    > > admit I'm not quite sure what's going on here.
    > >
    > > Could anyone explain this ? and what can I do to resolve this issue ?
    > >
    > >

    >
    >
    JezB, Jan 12, 2004
    #3
  4. Jeff,

    A coupde of weeks back there was a thread on using nulls in webservices. I
    haven't actually done this, but there are apparenly some problems. You may
    want to review. "codegen:nullValue Still not working for me" to see if its
    relevant to your situation.

    --
    Kathleen Dollard
    Microsoft MVP
    Author "Code Generation in Microsoft .NET"


    "JezB" <> wrote in message
    news:%...
    > You're right !! How did I miss this ?
    > Thanks.
    >
    > However, I'd still like to know why exposing a dataset as a webservice
    > changes the generated code.
    >
    > "Miha Markic" <miha at rthand com> wrote in message
    > news:...
    > > Hi JezB,
    > >
    > > For every property (field) that can be null there is a

    Is*fieldname*Null()
    > > method in typed dataset.
    > >
    > > --
    > > Miha Markic - RightHand .NET consulting & software development
    > > miha at rthand com
    > > www.rthand.com
    > >
    > > "JezB" <> wrote in message
    > > news:...
    > > > I'm using a typed dataset to get rows from a database, but getting an
    > > > invalid cast exception when trying to examine columns in that row

    which
    > > are
    > > > null in the database. This is because of some code generated within

    the
    > > > typed dataset's class (eg. myDataSet.cs) :-
    > > >
    > > > catch (InvalidCastException e) {
    > > > throw new StrongTypingException("Cannot get value because it is
    > > > DBNull.", e);
    > > > }
    > > >
    > > > I know I can force a change of this code by setting a NullValue

    property
    > > of
    > > > the specific elements within my dataset. However, when I expose the

    > > dataset
    > > > schema through a web service (it's exposed by having an exposed method
    > > > return a dataset of this type), this change seems to be ignored. It

    > seems
    > > to
    > > > regenerate the default code in a class file called Reference.cs - and

    I
    > > must
    > > > admit I'm not quite sure what's going on here.
    > > >
    > > > Could anyone explain this ? and what can I do to resolve this issue ?
    > > >
    > > >

    > >
    > >

    >
    >
    >
    Kathleen Dollard, Jan 12, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.microsoft.com
    Replies:
    0
    Views:
    430
    news.microsoft.com
    Apr 12, 2006
  2. Francisco Garcia
    Replies:
    2
    Views:
    465
    Fran Garcia
    Apr 13, 2006
  3. =?Utf-8?B?SXbDoW4gUMOpcmV6?=

    Typed Datasets - Performance over WebServices (1 Dst or Various Sm

    =?Utf-8?B?SXbDoW4gUMOpcmV6?=, Aug 14, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    337
    John Saunders [MVP]
    Aug 14, 2007
  4. Thomas Zaleski

    Webservices and strongly typed datasets

    Thomas Zaleski, Jul 9, 2003, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    124
    Thomas Zaleski
    Jul 9, 2003
  5. news.microsoft.com
    Replies:
    0
    Views:
    184
    news.microsoft.com
    Apr 12, 2006
Loading...

Share This Page