DBNull problems - typed datasets - webservices

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

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 ?
 
Hi JezB,

For every property (field) that can be null there is a Is*fieldname*Null()
method in typed dataset.
 
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.
 
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.
 
Back
Top