I don't want to enter the religious wars about NULLS and whether they should
or should not be allowed in Databases. I have a legacy database and I can't
change it. NULLS are a fact of life for me.

My question is whether anyone has a less labor intensive solution.

In the auto-generated class definition code for the datarow of eacch table
is code like the following...

Public Property Birthday As Date
Get
Try
Return CType(Me(Me.tableo_Person.BirthdayColumn),Date)
Catch e As InvalidCastException
Throw New StrongTypingException("Cannot get value
because it is DBNull.", e)
End Try
End Get
Set
Me(Me.tableo_Person.BirthdayColumn) = value
End Set
End Property

I have been modifying this code to...
Public Property Birthday As Date
Get
Try
Return CType(Me(Me.tableo_Person.BirthdayColumn),Date)
Catch e As InvalidCastException
return nothing
End Try
End Get
Set
if value = nothing then
Me(Me.tableo_Person.BirthdayColumn) = system.convert.dbnull
else
Me(Me.tableo_Person.BirthdayColumn) = value
endif
End Set
End Property

This code gets generated anytime I have to redrag a datatable into a
dataset. Then I have to go thru each field and modify as above again.

Is there a smarter way to do this? (I'm normally a foxpro programmer, but
this one is going against a SQL server database, if that has any bearing on
this question)
--
T Ralya, new .NET developer, HMSA

Re: non-labor intensive solution to Nulls in legacy DB by W

W
Mon Jan 03 14:07:50 CST 2005

Since you're using VB.nET you can easily use IIF with IsDBNull
http://www.knowdotnet.com/articles/handlingnullvalues.html

--
W.G. Ryan, MVP

www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"T Ralya" <TRalya@discussions.microsoft.com> wrote in message
news:A1A63330-E4F1-4827-AF79-FE44E8A1238C@microsoft.com...
> I don't want to enter the religious wars about NULLS and whether they
should
> or should not be allowed in Databases. I have a legacy database and I
can't
> change it. NULLS are a fact of life for me.
>
> My question is whether anyone has a less labor intensive solution.
>
> In the auto-generated class definition code for the datarow of eacch table
> is code like the following...
>
> Public Property Birthday As Date
> Get
> Try
> Return CType(Me(Me.tableo_Person.BirthdayColumn),Date)
> Catch e As InvalidCastException
> Throw New StrongTypingException("Cannot get value
> because it is DBNull.", e)
> End Try
> End Get
> Set
> Me(Me.tableo_Person.BirthdayColumn) = value
> End Set
> End Property
>
> I have been modifying this code to...
> Public Property Birthday As Date
> Get
> Try
> Return CType(Me(Me.tableo_Person.BirthdayColumn),Date)
> Catch e As InvalidCastException
> return nothing
> End Try
> End Get
> Set
> if value = nothing then
> Me(Me.tableo_Person.BirthdayColumn) =
system.convert.dbnull
> else
> Me(Me.tableo_Person.BirthdayColumn) = value
> endif
> End Set
> End Property
>
> This code gets generated anytime I have to redrag a datatable into a
> dataset. Then I have to go thru each field and modify as above again.
>
> Is there a smarter way to do this? (I'm normally a foxpro programmer, but
> this one is going against a SQL server database, if that has any bearing
on
> this question)
> --
> T Ralya, new .NET developer, HMSA



Re: non-labor intensive solution to Nulls in legacy DB by John

John
Mon Jan 03 14:35:17 CST 2005

"T Ralya" <TRalya@discussions.microsoft.com> wrote in message
news:A1A63330-E4F1-4827-AF79-FE44E8A1238C@microsoft.com...
>I don't want to enter the religious wars about NULLS and whether they
>should
> or should not be allowed in Databases. I have a legacy database and I
> can't
> change it. NULLS are a fact of life for me.
>
> My question is whether anyone has a less labor intensive solution.
>
> In the auto-generated class definition code for the datarow of eacch table
> is code like the following...
>
> Public Property Birthday As Date
> Get
> Try
> Return CType(Me(Me.tableo_Person.BirthdayColumn),Date)
> Catch e As InvalidCastException
> Throw New StrongTypingException("Cannot get value
> because it is DBNull.", e)
> End Try
> End Get
> Set
> Me(Me.tableo_Person.BirthdayColumn) = value
> End Set
> End Property

When I generate a strongly-typed DataSet from a database which has columns
which allow NULL, it also generates an Is<columnName>Null method. Do you
have such a method? If not, I wonder why it didn't think the Birthday column
allowed NULL?

John Saunders



Re: non-labor intensive solution to Nulls in legacy DB by TRalya

TRalya
Mon Jan 03 15:01:05 CST 2005

I hadn't noticed that procedure before, but yes it did generate it. I can
use that to handle the situation ourside of the dataset.vb code. Thanks
bunches.

"John Saunders" wrote:

> "T Ralya" <TRalya@discussions.microsoft.com> wrote in message
> news:A1A63330-E4F1-4827-AF79-FE44E8A1238C@microsoft.com...
> >I don't want to enter the religious wars about NULLS and whether they
> >should
> > or should not be allowed in Databases. I have a legacy database and I
> > can't
> > change it. NULLS are a fact of life for me.
> >
> > My question is whether anyone has a less labor intensive solution.
> >
> > In the auto-generated class definition code for the datarow of eacch table
> > is code like the following...
> >
> > Public Property Birthday As Date
> > Get
> > Try
> > Return CType(Me(Me.tableo_Person.BirthdayColumn),Date)
> > Catch e As InvalidCastException
> > Throw New StrongTypingException("Cannot get value
> > because it is DBNull.", e)
> > End Try
> > End Get
> > Set
> > Me(Me.tableo_Person.BirthdayColumn) = value
> > End Set
> > End Property
>
> When I generate a strongly-typed DataSet from a database which has columns
> which allow NULL, it also generates an Is<columnName>Null method. Do you
> have such a method? If not, I wonder why it didn't think the Birthday column
> allowed NULL?
>
> John Saunders
>
>
>