Click here to Skip to main content
16,004,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim InveststrBuilder1 As New StringBuilder
 If Trim(RSmartUtl.DtFormat) = "DD-MM-YYYY" Then
                                    InveststrBuilder1.Append("document.forms[0].INVEST_POLICY_DATE_DD.value=unescape('" & Format(DatePart(DateInterval.Day, objDR("DOC_DATE")), "00") & "');" & vbCrLf)
                                    InveststrBuilder1.Append("document.forms[0].INVEST_POLICY_DATE_MM.value=unescape('" & Format(DatePart(DateInterval.Month, objDR("DOC_DATE")), "00") & "');" & vbCrLf)
                                End If
                                If Trim(RSmartUtl.DtFormat) = "MM-DD-YYYY" Then
                                    InveststrBuilder1.Append("document.forms[0].INVEST_POLICY_DATE_DD.value=unescape('" & Format(DatePart(DateInterval.Month, objDR("DOC_DATE")), "00") & "');" & vbCrLf)
                                    InveststrBuilder1.Append("document.forms[0].INVEST_POLICY_DATE_MM.value=unescape('" & Format(DatePart(DateInterval.Day, objDR("DOC_DATE")), "00") & "');" & vbCrLf)
                                End If
                                InveststrBuilder1.Append("document.forms[0].INVEST_POLICY_DATE_YY.value=unescape('" & Format(DatePart(DateInterval.Year, objDR("DOC_DATE")), "0000") & "');" & vbCrLf)
When Date is null in database i.e back end I get the error
Conversion from type 'DBNull' to type 'Date' is not valid.
Posted
Updated 8-Apr-14 20:10pm
v2

Check for DBNull.Value[^] before you start processing with date...
 
Share this answer
 
Comments
Member 9410081 9-Apr-14 2:23am    
No still didn't get proper solution.
Maciej Los 9-Apr-14 2:34am    
:laugh:
Have you wrote any if... then... else... end if statement?
objDR("DOC_DATE") contains data retrieved from a database, doesn't it? And there in the database, the corresponding column may contain NULL, which gets translated into DBNull when you retireve the data into your .Net program.
The DatePart function then tries to cast that into a DateTime variable and fails: DateTime is a value type and must not be null.
Hence check for objDR("DOC_DATE") being DBNull.Value before you do that processing, as Macej told you:
VB
If objDR("DOC_DATE") = DBNull.Value Then
    MessageBox.Show("No date given!")
Else
    'your code from above
EndIf
 
Share this answer
 
v2
Comments
Member 9410081 9-Apr-14 3:52am    
Thanks
Maciej Los 9-Apr-14 4:17am    
Does it exactly what i was trying to tell you?
Please, accept my answer as a solution (green button) and vote-up both answers. This is the way how we say "Thank you" ;)
Maciej Los 9-Apr-14 4:17am    
+5
Bernhard Hiller 9-Apr-14 4:21am    
Thanks. Looks like the guy needed some more background information, and perhaps also some spoon-feeding...
Maciej Los 9-Apr-14 5:36am    
Yes. He needs to back to basics!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900