SQL Server DB I am new to c# and SQL server... I insert value 1 if a checkbox is selected other insert value 0 in SQL server and added text box for id. If I type id in the text box and click the update button the 1vvalue from SQL server update the checkbox as selected help me to solve the problem
private void add_recipe_Click(object sender, EventArgs e)
{
string engine1 = "";
string engine2 = "";
string engine3 = "";
if(e1.Checked)
{
engine1 = "1";
}
else
{
engine1="0";
}
if (e2.Checked)
{
engine2 = "1";
}
else
{
engine2 = "0";
}
if (e3.Checked)
{
engine3 = "1";
}
else
{
engine3 = "0";
}
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into Table_3 (id,part1,part2,part3) values('" + textBox1.Text+"','"+engine1+"','"+engine2+"','"+engine3+"') ";
cmd.ExecuteNonQuery();
con.Close();
dataupdate();
MessageBox.Show("Recipe Inserted");
}
public void dataupdate()
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT id from Table_3 ";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.ScrollBars = ScrollBars.None;
con.Close();
}
Aucun commentaire:
Enregistrer un commentaire