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 30 31 32 33 34 35 36 37 38 39 40 41 42
| public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Enregistrer_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection("Data Source = user-tosh\\Sqlexpress ;database=yosra;User ID =sa;Password=med;");
SqlDataAdapter da = new SqlDataAdapter();
//da.InsertCommand = new SqlCommand("INSERT INTO exemple (Nom,Prenom) VALUES (@Nom, @Prenom)", cs);
//da.InsertCommand = new SqlCommand("INSERT INTO exemple (CIN) VALUES (@CIN)", cs);
//da.InsertCommand = new SqlCommand("INSERT INTO exemple (Description) VALUES (@Description)", cs);
da.InsertCommand = new SqlCommand("INSERT INTO exemple(Nom,Prenom,CIN,Description) VALUES (@Nom,@Prenom,@CIN,@Description)", conn);
da.InsertCommand.Parameters.Add("@Nom", SqlDbType.VarChar).Value = txtNom.Text;
da.InsertCommand.Parameters.Add("@Prenom", SqlDbType.VarChar).Value =txtPrenom.Text;
da.InsertCommand.Parameters.Add("@CIN", SqlDbType.Int).Value = txtCIN.Text;
da.InsertCommand.Parameters.Add("@Description", SqlDbType.Text).Value = Description.Text;
conn.Open();
da.InsertCommand.ExecuteNonQuery();
conn.Close(); |
Partager