non-labor intensive solution to Nulls in legacy DB

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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 said:
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
 
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.
 
Back
Top