allanlorriman
asked on
date exception - vb.net
Hello,
I am using the following statement on one of the page and I get an error sometimes if the user is outside the GB format
Dim Query As String = "UPDATE IQResults SET IsCompleted='True', EndTime=GetDate() Where resultid =(SELECT max(resultid) FROM IQResults where CustomerID='" & CustomerID & "')"
Dim MyCommand As SqlCommand = New SqlCommand(Query, MySqlConnection)
MyCommand.Connection.Open( )
MyCommand.ExecuteNonQuery( )
MyCommand.Connection.Close ()
pnlTestComplete.Visible = True
Exception
>>InvalidCastException: Conversion from string "26/03/1991" to type 'Date' is not valid.
Can someone please advice how can I fix this?
Thanks
I am using the following statement on one of the page and I get an error sometimes if the user is outside the GB format
Dim Query As String = "UPDATE IQResults SET IsCompleted='True', EndTime=GetDate() Where resultid =(SELECT max(resultid) FROM IQResults where CustomerID='" & CustomerID & "')"
Dim MyCommand As SqlCommand = New SqlCommand(Query, MySqlConnection)
MyCommand.Connection.Open(
MyCommand.ExecuteNonQuery(
MyCommand.Connection.Close
pnlTestComplete.Visible = True
Exception
>>InvalidCastException: Conversion from string "26/03/1991" to type 'Date' is not valid.
Can someone please advice how can I fix this?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
where as contactdetails.dateofbirth is
Public Property DateOfBirth() As String
Get
Return Me._DateOfBirth
End Get
Set(ByVal value As String)
Me._DateOfBirth = value
End Set
End Property
Public Property DateOfBirth() As String
Get
Return Me._DateOfBirth
End Get
Set(ByVal value As String)
Me._DateOfBirth = value
End Set
End Property
ASKER
Public Shared Function Age(ByVal Birthdate As System.DateTime) As Long
Try
Dim CurrentDate As System.DateTime = System.DateTime.Today
Select Case Month(Birthdate)
Case Is < Month(System.DateTime.Today)
Age = DateDiff("YYYY", Birthdate, Now())
Case Is = Month(CurrentDate)
Select Case Day(Birthdate)
Case Is < Day(CurrentDate)
Age = DateDiff("YYYY", Birthdate, Now())
Case Is = Day(CurrentDate)
Age = DateDiff("YYYY", Birthdate, Now())
Case Is > Day(CurrentDate)
Age = DateDiff("YYYY", Birthdate, Now()) - 1
End Select
Case Is > Month(CurrentDate)
Age = DateDiff("YYYY", Birthdate, Now()) - 1
Case Else
Age = 0
End Select
Catch ex As System.Exception
'Error handling code does here
End Try
End Function
ASKER
Thanks CodeCruiser
For my other query I will open a new question...
For my other query I will open a new question...
why is your property (Public Property DateOfBirth() As String) declared as a string?
ASKER
ASKER
Hi Eric
thanks for looking into this for me, it was one of the old property which was being used elsewhere as well, I thought I could reuse in the code...
this is causing a problem now, can you advice a solution please? do not want to change the property as its being in reference on other places...
thank you
thanks for looking into this for me, it was one of the old property which was being used elsewhere as well, I thought I could reuse in the code...
this is causing a problem now, can you advice a solution please? do not want to change the property as its being in reference on other places...
thank you
Create another readonly property that would return a DateOfBirth in datetime format to pass to your methods
ASKER
>> System.InvalidCastExceptio
please can you advice whats wrong with this code?
Open in new window