Bonjour à tous !!
J'ai un petit soucide compréhension lorsque j'utilise les objets dataset et datadapter afin d'insérer une ligne dans ma base de données.
J'ai fait ceci, sui fonctionne:
J'arrive bien à insérer une valeur dans ma table qui contient un seul champs.
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 public string IAmConnected() { DataSet oDataSet; OdbcDataAdapter oDataAdapter; BD bd = new BD(); OdbcConnection con = bd.Connect(); oDataAdapter = new OdbcDataAdapter("select * from connected", con); oDataSet = new DataSet("Connected"); oDataAdapter.Fill(oDataSet, "Connected"); oDataAdapter.InsertCommand = new OdbcCommand("INSERT INTO connected(LOGIN) Values(?)", con); oDataAdapter.InsertCommand.Parameters.Add("@LOGIN", OdbcType.VarChar, 10, "LOGIN"); DataRow oDataRow; oDataRow = oDataSet.Tables["Connected"].NewRow(); oDataRow["LOGIN"] = this.login; oDataSet.Tables["Connected"].Rows.Add(oDataRow); try { oDataAdapter.Update(oDataSet, "Connected"); } catch (Exception e) { return e.Message.ToString(); //Response.Write(e.Message.ToString()); } con.Close(); return "1"; }
Mais comment faire pour insérer un enregistrement dans une table qui contient plusieurs champs (2 par exemple ??)
Merci pour vos réponses !!!
Partager