Professional Web Applications Themes

DBNull problems - typed datasets - webservices - ASP.NET Web Services

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 ...

  1. #1

    Default DBNull problems - typed datasets - webservices

    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 Guest

  2. #2

    Default Re: DBNull problems - typed datasets - webservices

    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
    [url]www.rthand.com[/url]

    "JezB" <jeremy.bradshawblueyonder.co.yk> wrote in message
    news:eJAisoQ2DHA.1924TK2MSFTNGP10.phx.gbl...
    > 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 Guest

  3. #3

    Default Re: DBNull problems - typed datasets - webservices

    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:Ozr5s0Q2DHA.1532TK2MSFTNGP10.phx.gbl...
    > 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
    > [url]www.rthand.com[/url]
    >
    > "JezB" <jeremy.bradshawblueyonder.co.yk> wrote in message
    > news:eJAisoQ2DHA.1924TK2MSFTNGP10.phx.gbl...
    > > 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 Guest

  4. #4

    Default Re: DBNull problems - typed datasets - webservices

    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" <jeremy.bradshawblueyonder.co.yk> wrote in message
    news:%23tiy3GR2DHA.2316TK2MSFTNGP10.phx.gbl...
    > 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:Ozr5s0Q2DHA.1532TK2MSFTNGP10.phx.gbl...
    > > 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
    > > [url]www.rthand.com[/url]
    > >
    > > "JezB" <jeremy.bradshawblueyonder.co.yk> wrote in message
    > > news:eJAisoQ2DHA.1924TK2MSFTNGP10.phx.gbl...
    > > > 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 Guest

Similar Threads

  1. WebServices and Datasets
    By JJ in forum ASP.NET Web Services
    Replies: 5
    Last Post: April 27th, 12:51 AM
  2. Problems returning Datasets
    By Andy Barker in forum ASP.NET Web Services
    Replies: 1
    Last Post: August 1st, 07:47 PM
  3. Typed dataset used by two webservices problem
    By Simon Storr in forum ASP.NET Web Services
    Replies: 2
    Last Post: February 26th, 02:09 AM
  4. Typed DataSets, Web services and namespace confusion...
    By Ben in forum ASP.NET Web Services
    Replies: 3
    Last Post: July 10th, 03:10 AM
  5. Webservices and strongly typed datasets
    By Thomas Zaleski in forum ASP.NET Web Services
    Replies: 0
    Last Post: July 9th, 03:38 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139