Hi,
I am trying to get to grips with the “NULL” dates in SQL database.
Q1) The PrepareDateForDb code works OK on an update of a record, but when I try add a record with a null date it throws an exception?
Q2) The date time when I retrieve the datetime stored in the database as ToOADate format, the date time is a day out. I assume as I use a UK date time it is placing my date two hours behind. My customers may not have the same datetime location.
Thanks
This works OK![]()
This throws an exceptionCode:strSQL = "UPDATE [Business] SET" & _ ... " ,DateVerified = " & PrepareDateForDb(mtbDateVerified.Text) & _ ...![]()
Code:... With cmSQL ... .Parameters.Add(New SqlParameter("@DateVerified", SqlDbType.DateTime)).Value = PrepareDateForDb(mtbDateVerified.Text)Code:‘ Prepare date for inserting into database Function PrepareDateForDb(ByVal strValue As String) As String 'Empty MaskedTextBox field gives “ / /” If strValue.StartsWith(" ") Then Return "NULL" Exit Function End If 'Empty date field If strValue.Trim() = "" Then Return "NULL" Else 'Convert date to ToOADate Dim strDt As String = CDate(strValue).ToOADate Return strDt End If End Function




Reply With Quote