1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| private void btn_click(object sender, EventArgs e)
{
string strRequete = "INSERT INTO [dbo].[tb1] ([nom], [id1], [id2], [id3]) VALUES (@nom, @id1, @id2, @id3)";
try
{
SqlCommand oCommand = new SqlCommand(strRequete);
oCommand.Parameters.Add(new SqlParameter("@nom", SqlDbType.Int, 4));
oCommand.Parameters.Add(new SqlParameter("@id1", SqlDbType.Int, 4));
oCommand.Parameters.Add(new SqlParameter("@id2", SqlDbType.Int, 4));
oCommand.Parameters.Add(new SqlParameter("@id3", SqlDbType.Int, 4));
oCommand.Parameters["@nom"].Value = Convert.ToInt32( textBox1.Text);
oCommand.Parameters["@id1"].Value = Convert.ToInt32( textBox2.Text);
oCommand.Parameters["@id2"].Value = Convert.ToInt32(textBox3.Text);
oCommand.Parameters["@id3"].Value = Convert.ToInt32(textBox4.Text);
oCommand.Connection.Open();
oCommand.ExecuteNonQuery();
oCommand.Connection.Close();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
} |
Partager