I tried rewrite other ways but the code always showing error like this
System.Data.SqlClient.SqlException: 'Incorrect syntax near 'student'
The error occurs on the line
cmd.ExecuteNonQuery();
I hope someone will be able to help.
private void button1_Click(object sender, EventArgs e)
{
if (StudUsn.Text == "" || StudName.Text == "" ||
FatherName.Text == "" || MotherName.Text == "" ||
AddressTb.Text == "" || CollegeTb.Text == "")
{
MessageBox.Show("No empty filled accepted");
}
else
{
Con.Open();
String query = "insert into Student_tbl values(" + StudUsn.Text + ",'" + FatherName.Text + "','" + MotherName.Text + "','" + AddressTb.Text + "','" + CollegeTb.Text + "','" + StudRoomCb + "','" + StudStatusCb + "')";
SqlCommand cmd = new SqlCommand(query, Con);
cmd.ExecuteNonQuery();
MessageBox.Show("Student successfully added");
Con.Close();
updateBookedStatus();
FillStudentDGV();
FillStudentCombobox();
}
}