When setting codes using the INSERT INTO sql command the following error occurs.
"Conversion failed when converting date and/or time from character string."
Values of date & time are read from a datetime picker in form.
How can I Fix this issue?
{
String conString = @"Data Source=DESKTOP-2V4K24T\SQLEXPRESS;Initial Catalog=Student_Enrollment_System_DB;Integrated Security=True";
string query = "INSERT INTO Students(Registration_Number,Student_Name,Date_of_Birth,Gender,Contact_Number,Course_enrolled_in) " +
"VALUES('" + RegNo.Text + "','" + StuName.Text + "','" + this.DateOfBirth.Text + "','" + textBox1.Text + "','" + ContactNo.Text + "','" + CsesEnrolledIn.Items + "')";
SqlConnection conn;
conn = new SqlConnection(conString);
SqlCommand runquery = new SqlCommand(query, conn);
conn.Open();
runquery.ExecuteNonQuery();
MessageBox.Show("Student have been added!");
}