Hi,
At my database I have a table with date field.. Which has NULL /empty values when nothing is added to the backend table.
DateDisabled, datatype - datetime.
Now at the front end I have an application wchic pulls these records in a select statement as shown....
It gives me at runtime an error message;
Conversion from string "00/00/00" to type Date is not valid.
This is when the datedisabled is NULL in the backend database. To be honest I rather pull out an emoty string when empty/NULL, because there is a calendar to enter a date.
Also, datedisabled can be NULL at one time so we need to accomodate a situation where the value is NULL or empty.
A way round is to make the datedisabled field with the datatype varchar(50)... and save the date as string and not date. I have done that and it works fine but I still want to have datetime datatype for the field on the SQL table..
Any suggestions or help please
Thank you
At my database I have a table with date field.. Which has NULL /empty values when nothing is added to the backend table.
DateDisabled, datatype - datetime.
Now at the front end I have an application wchic pulls these records in a select statement as shown....
Code:
Dim OrgDetails As New System.Data.SqlClient.SqlCommand(("Select..................
Using reader As System.Data.SqlClient.SqlDataReader = OrgDetails.ExecuteReader()
While reader.Read()
Dim DateDisabled As Date = FixNullDate(reader.GetValue(13))
txtdatedisabled.Text = DateDisabled
End While
End Using
Code:
Public Shared Function FixNullDate(ByVal dbvalue) As Date
If dbvalue Is DBNull.Value Then
Return "00/00/00"
Else
'NOTE: This will cast value to string if
'it isn't a string.
Return dbvalue
End If
End Function
Conversion from string "00/00/00" to type Date is not valid.
This is when the datedisabled is NULL in the backend database. To be honest I rather pull out an emoty string when empty/NULL, because there is a calendar to enter a date.
Also, datedisabled can be NULL at one time so we need to accomodate a situation where the value is NULL or empty.
A way round is to make the datedisabled field with the datatype varchar(50)... and save the date as string and not date. I have done that and it works fine but I still want to have datetime datatype for the field on the SQL table..
Any suggestions or help please
Thank you