I am having trouble getting my vb.net program to update a date value in my SQL Server database.
The datatype for the field 'Date Out' is set to 'date' type in the database.
The code i am using to update the database fields and date is as follows:
I have tried several methods of supplying the 'Date Out' value to the SQL database. The above sample is using a 'Date time picker' i have also tried manually submitting the date using the below code:Code:Dim cmd As SqlCommand = New SqlCommand cmd.CommandTimeout = "60" cmd.CommandType = CommandType.Text cmd.CommandText = "UPDATE Job SET Status='" & CBEquipmentTestRepairStatus.SelectedItem & "', Report='" & TBEquipmentTestTestReport.Text & "', [Beyond Economical Repair]='No', Forename='" & TBEquipmentTestForename.Text & "', Surname='" & TBEquipmentTestSurname.Text & "', [Date Out]='" & DTPEquipmentTestDateOut.Value & "' WHERE [Returns ID]='" & DGVEquipmentTest(7, currentr).Value & "'" cmd.Connection = con cmd.ExecuteReader(CommandBehavior.Default)
Using the above two methods the database comes back with the error 'Conversion failed when converting date and/or time from character string' . The only time i have ever successfuly got the date to add to the database was when i manually typed in '1/12/2010' into the SELECT statement.Code:Dim testdate As Date = New Date(My.Computer.Clock.LocalTime.Year, My.Computer.Clock.LocalTime.Month, My.Computer.Clock.LocalTime.Day)
Any help would be very much appreciated




Reply With Quote