J
James
Hello,
I am trying to create a Function to test TextBoxes and convert the Text to
DateTime if not empty.
My code is :
Public Shared Function GetDateTime(ByVal DateValue As String) As String
If Not String.IsNullOrEmpty(DateValue) Then
Return DateTime.Parse(DateValue)
Else
Return Nothing
End If
End Function
Then in a OnClick command I have:
CurrentMember.StartDate = GetDateTime(txtStartDate.Text)
It works ok when there is a date but if its empty I get an error message:
System.InvalidCastException: Conversion from string "" to type 'Date' is not
valid.
If I do CurrentMember.StartDate = Nothing it works fine so no problem with
Null values in the field.
Does anyone have any suggestions as this has puzzled me for too long now.
Thanks in advance
James
I am trying to create a Function to test TextBoxes and convert the Text to
DateTime if not empty.
My code is :
Public Shared Function GetDateTime(ByVal DateValue As String) As String
If Not String.IsNullOrEmpty(DateValue) Then
Return DateTime.Parse(DateValue)
Else
Return Nothing
End If
End Function
Then in a OnClick command I have:
CurrentMember.StartDate = GetDateTime(txtStartDate.Text)
It works ok when there is a date but if its empty I get an error message:
System.InvalidCastException: Conversion from string "" to type 'Date' is not
valid.
If I do CurrentMember.StartDate = Nothing it works fine so no problem with
Null values in the field.
Does anyone have any suggestions as this has puzzled me for too long now.
Thanks in advance
James