SqlConnection sqlconnection = new SqlConnection("Data Source=(local);Initial Catalog=supermarket;Integrated Security=True");
SqlCommand sqlcom = new SqlCommand();
sqlcom.Connection = sqlconnection;
try
{
sqlconnection.Open();
if (radioButton1.Checked)
{
sqlcom.CommandText = "insert into CUSTOMERS values('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox1.Text+ "','" + radioButton1.Text + "')";
sqlcom.ExecuteNonQuery();
sqlconnection.Close();
MessageBox.Show("Inserted successfully! ");
}
if(radioButton2.Checked)
{
sqlcom.CommandText = "INSERT INTO CUSTOMERS VALUES('" + textBox2.Text + "','" +textBox3.Text + "','" + textBox1.Text + "','" + radioButton2.Text + "')";
sqlcom.ExecuteNonQuery();
sqlconnection.Close();
MessageBox.Show("Inserted successfully! ");
}
}
catch (Exception)
{
MessageBox.Show("Error inserting Customer or Customer already exists!");
}
}