Bonjour en fait je debut en C# et je ss entrain de faire un formulaire avec les winforms et j'aimerai le stocker mes informations dans une base de donnee je vous montres mon code
mon probleme est le suivant lorsque je clique mon bouton send aucune action ne se produit les donnees ne se sont pas envoyer dans la base je compte sur votre aide.Merci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
43
44
45
46
47
48
49 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Simple_test_deconnecte_2 { public partial class Form1 : Form { public SqlConnection connection; public SqlDataAdapter myDa; public DataSet myDs; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the '_leader_databaseDataSet.Products' table. You can move, or remove it, as needed. this.productsTableAdapter.Fill(this._leader_databaseDataSet.Products); connection = new SqlConnection(); myDa = new SqlDataAdapter(); myDs = new DataSet(); //connection à la base myDa.InsertCommand = new SqlCommand(); myDa.InsertCommand.Connection = connection; connection.ConnectionString = "Data Source=(local)\\SQLEXPRESS;Initial Catalog=leader-database;Integrated Security=True;Pooling=False"; myDa.InsertCommand.CommandText = "INSERT INTO Products (Name) " + "VALUES (@nom)"; myDa.InsertCommand.Parameters.Add("@nom", SqlDbType.NVarChar, 50, "Name"); } private void bt_send_Click(object sender, EventArgs e) { dataGridView1.DataSource = _leader_databaseDataSet.Products; } } }
Partager