Gary Ranson
11/11/2002 10:12:00 AM
Bonnie,
If Derek is using a typed dataget generated with MSDataSetGenerator the
better method would be ...
<typeddataset>.<typeddatatable>.<field>IsNull.
This is a public property and has a getter and setter.
So ...
if(value==null) row.<field>IsNull=true; else row.<field>=value;
"Bonnie Berent" <bonnieb@profitware-online.com> wrote in message
news:#wFfVf7hCHA.2240@tkmsftngp12...
> Derek,
>
> I've encountered similar problems with NULLs. I don't know if there are
> other workarounds, but I have found that if I need to access a particular
> field, I have to use the old un-typed notation to first see if it's a
NULL
> or not. So, if I need to check an integer field, for example like this:
>
> if (ds.MyTable[nRow].MyField == 1)
>
> it will blow up if MyField happens to be NULL. But, if you do this
instead:
>
> if (ds.MyTable[nRow]["MyField"] != DBNull.Value &&
ds.MyTable[nRow].MyField
> ==1)
>
> then it will handle the NULL situation. I know, it kinda sucks because it
> you have to resort to using some of the non-typed dataset notation, but
it's
> the only way that I've found around it.
>
>
>
> ~~Bonnie
>
>
> "Derek Lakin" <dlakin@mass.co.uk> wrote in message
> news:uarjedwhCHA.1860@tkmsftngp09...
> > I have an MSAccess database table that contains string and numeric
> columns.
> > For some rows, sometimes, some of the columns contain null values.
> >
> > Having used Server Explorer in VS.NET, I now have a strongly-typed
dataset
> > and the necessary OleDbDataAdapter. After the call to Fill when
inspecting
> > the data set in the debugger, all of the null fields (string and int)
have
> > the message: "<error: an exception of type:
> > {System.Data.StrongTypingException} occurred>".
> >
> > For the int columns I could understand this being because you can't cast
a
> > null to an int, but I'm not sure about the string columns.
> >
> > This then causes a failure to occur when trying to insert or update data
> and
> > commiting to the database (it can't translate an exception to a valid
> value
> > to produce the sql statement) and no doubt causes other databinding
issues
> > as well.
> >
> > Surely I'm not the first or only person to have null values in columns
> when
> > producing a .NET application (using C# in this case)!? Someone must have
> > come across this and worked out a way round it, the question is how?
> >
> >
>
>