I used to query:
Dim a As String
a = "INSERT INTO tblVisitor(Name, Sex, TimeIn, EnterDate)
VALUES('"& txtName.Text &"', '"& cboSex.Text &"', '"& Now() &"', '"& DateTime.Parse(cboEnterDate.Text) &"')"
myCommand = New SqlCommand(a, myConnection)
myCommand.ExecuteNonQuery()
........................................
Which cboEnterDate is my DateTime Picker. Then I got the message:
Conversion failed when converting date time from character string.
Please help.
By constructing a string, you a) open yourself to SQL injection, and b) end up converting strings to datetimes to strings to datetimes.
If, instead, you use parameters:
Which only performs a single conversion of string to datetime. Although, if
cboEnterDateis a DateTimePicker, you can avoid treating it as a string at all: