I have a problem with inserting date into a database and displaying it.
I use Visual Basic 2013 with Microsoft SQL database file.
I have a table called Appointments, there is a column called Date with a type of date.
I have a form with a DateTimePicker displaying date in this format "dd/MM/yyyy" my computer regional settings.
When I try to insert it into the database, by obtaining the date from the DateTimePicker as follows:
DateTimePicker1.Value.Date
I still get an error. I know that Microsoft SQL only takes this format "MM/dd/yyyy", but is there any way to convert from "dd/MM/yyyy" to "MM/dd/yyyy" using visual basic and sql?
Dim con As New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=" + My.Settings.strTextbox + ";Integrated Security=True;Connect Timeout=30")
Dim cmd As New SqlCommand("insert into Appointment (AssignDoc,Date,TimeFrom,FileNo) values (@AssignDoc,@Date,@TimeFrom,@FileNo)")
cmd.Connection = con
con.Open()
cmd.Parameters.AddWithValue("@AssignDoc", ComboBox6.SelectedItem)
cmd.Parameters.AddWithValue("@Date", DateTimePicker1.Value.Date)
cmd.Parameters.AddWithValue("@TimeFrom", ComboBox1.SelectedItem)
cmd.Parameters.AddWithValue("@FileNo", TextBox2.Text)
Dim reader As SqlDataReader = Nothing
Try
cmd.ExecuteNonQuery()
con.Close()
'CreateAppointment()
MsgBox("Appointment Created Successfully", MsgBoxStyle.Information, "Appointment Created")
TextBox1.Text = ""
TextBox2.Text = ""
Catch ex As System.Exception
MsgBox(ex.Message)
End Try