G
Guest
I am having problems with the following code and hope someone can explain
this to me. Here is the routine that is having the problems:
Private Shared Sub LoadSubscriptionFromDataRow(ByVal s As Subscription,
ByVal dr As DataRow)
With dr
With s
.SubscriptionId = .Item(CN_SubscriptionId)
.UserId = CType(.Item(CN_UserId), Integer)
.BillToId = CType(.Item(CN_BillToId), Integer)
* .OrderDate = CType(.Item(CN_OrderDate), Date)
.ProductId = .Item(CN_ProductId)
.LicQty = CType(.Item(CN_LicQty), Short)
* .RenewalDate = CType(.Item(CN_RenewalDate), Nullable(Of Date))
.LastInvType = .Item(CN_LastInvType)
.LastInvSeq = CType(.Item(CN_LastInvSeq), Short)
.AbaNo = .Item(CN_AbaNo)
.TaxStatus = .Item(CN_TaxStatus)
.BillingComment = .Item(CN_BillingComment)
* * .CancelDate = CType(.Item(CN_CancelDate), Nullable(Of Date))
.CancelCode = .Item(CN_CancelCode)
* .LastMaintDate = CType(.Item(CN_LastMaintDate), Date)
End With
End With
End Sub
Each of the lines flaged above throws an execption.
Conversion from string "" to type 'Date' is not valid.
but upon examinatiopn of one of the data items, it is a valid date:
+dr.Item("OrderDate") #5/23/1990# {Date} Object
Date #5/23/1990# Date
and the funny thing is that by changing the line to ....dr.item(... the
exception goes away! So, it must have someting to do with the 'with dr'.
Also funny that the problem only occurs on 'Date' types.
On the line with 2 '**'s, the above exception changes to:
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
the value is System.VBNull. I guess I have to handle the case where the
date comming from the DB is null in some other way, but I thought this was
the reason for Nullable(Of T).
this to me. Here is the routine that is having the problems:
Private Shared Sub LoadSubscriptionFromDataRow(ByVal s As Subscription,
ByVal dr As DataRow)
With dr
With s
.SubscriptionId = .Item(CN_SubscriptionId)
.UserId = CType(.Item(CN_UserId), Integer)
.BillToId = CType(.Item(CN_BillToId), Integer)
* .OrderDate = CType(.Item(CN_OrderDate), Date)
.ProductId = .Item(CN_ProductId)
.LicQty = CType(.Item(CN_LicQty), Short)
* .RenewalDate = CType(.Item(CN_RenewalDate), Nullable(Of Date))
.LastInvType = .Item(CN_LastInvType)
.LastInvSeq = CType(.Item(CN_LastInvSeq), Short)
.AbaNo = .Item(CN_AbaNo)
.TaxStatus = .Item(CN_TaxStatus)
.BillingComment = .Item(CN_BillingComment)
* * .CancelDate = CType(.Item(CN_CancelDate), Nullable(Of Date))
.CancelCode = .Item(CN_CancelCode)
* .LastMaintDate = CType(.Item(CN_LastMaintDate), Date)
End With
End With
End Sub
Each of the lines flaged above throws an execption.
Conversion from string "" to type 'Date' is not valid.
but upon examinatiopn of one of the data items, it is a valid date:
+dr.Item("OrderDate") #5/23/1990# {Date} Object
Date #5/23/1990# Date
and the funny thing is that by changing the line to ....dr.item(... the
exception goes away! So, it must have someting to do with the 'with dr'.
Also funny that the problem only occurs on 'Date' types.
On the line with 2 '**'s, the above exception changes to:
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
the value is System.VBNull. I guess I have to handle the case where the
date comming from the DB is null in some other way, but I thought this was
the reason for Nullable(Of T).