I am getting "conversion failed when converting date and or time from character string".I have a function which for converting datetimpicker value to specific date format. and I am calling that in a sql query . please correct me where i am wrong.this is my function for converting datetimepicker value to my specific format:
Public Function convertDateTimePickerToDate(ByVal Datevalue As DateTimePicker) As Date
Dim convertedDate As Date
Dim format = "dd-MMM-yyyy"
Dim dateString As String = Datevalue.Value.ToString(format)
convertedDate = Date.ParseExact(dateString, format, Nothing)
Return convertedDate
End Function
and in my sql query i am calling it as:-
sql = "INSERT INTO SIM_SALES VALUES('" & txt_simNO.Text & "','" &txt_simMSISDN.Text & "','" & txt_simCustName.Text & "','" & convertDateTimePickerToDate(dtp_simSaleDate) & "')"
please correct me where I am wrong. or is there any other suggestions through which i can implement the same logic. thanks in advance