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