I keep getting an error when I run my code. Here’s the error “The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated”. It points to this part of my code…
Private Sub TestDate() Dim DateClosedString As String = "Closed" Dim cnn As Data.SqlClient.SqlConnection Dim cmd As Data.SqlClient.SqlCommand Dim TodayTest As Date = Today Dim strSQL2 As String strSQL2 = "Update TestTBL SET DateStatus = '" & DateClosedString & "' WHERE EndDate >= '" & Today & "'" Dim conn As String conn = "Data Source=.\SQLEXPRESS;AttachDbFilename=""|DataDirectory|\aspnetdb.mdf"";Integrated Security=True;User Instance=True" cnn = New Data.SqlClient.SqlConnection(conn) cmd = New Data.SqlClient.SqlCommand(strSQL2, cnn) cnn.Open() cmd.ExecuteNonQuery() cnn.Close() End Sub
The dates are saved to the database as DateTime. This is copy and passed from an enddate field in my database “22/05/2007 00:00:00”. I’m not really need the time part but I cant find any other way.
Can anyone help? I’ve been pulling my hair out over this one for days.