Bonjour, je rencontre un probleme sur la mise à jour d'une base de donnée en SQL.
mon code est le suivant :
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 public int update(DataTable dttable, string chaine) { try { if (connect != null) { //Transaction SqlTransaction myTrans = connect.BeginTransaction(); SqlCommand sqlcomm = new SqlCommand(chaine, connect, myTrans); SqlDataAdapter sqldataadapter = new SqlDataAdapter(sqlcomm); SqlCommandBuilder sqlcommbuilder = new SqlCommandBuilder(sqldataadapter); sqldataadapter.UpdateCommand = sqlcommbuilder.GetUpdateCommand(); sqldataadapter.InsertCommand = sqlcommbuilder.GetInsertCommand(); sqldataadapter.DeleteCommand = sqlcommbuilder.GetDeleteCommand(); sqldataadapter.MissingSchemaAction = MissingSchemaAction.AddWithKey; try { int result = sqldataadapter.Update(dttable); myTrans.Commit(); return result; } catch (DBConcurrencyException e) { myTrans.Rollback(); } } return 0; } catch(Exception e) { return -1; } }
et il est appellé par le webservice suivant :
la connexion à la base de donnée fonctionne, et l'erreur se situe sur sqldataadapter.UpdateCommand = sqlcommbuilder.GetUpdateCommand() qui me renvoit directement sur le catch. En quotant ces lignes, je n'arrive pas au catch, mais result prend la valeur 0 et la mise a jour n'est pas effectué.
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 [WebMethod] public int updateRecette(string Table, string nom, string diff, string tmp_prepa, string nb_personne, string calorie, string desc) { DataTable dt = new DataTable(); DataTable dtTable = new DataTable(Table); dal.Connex_SQL2005(); string update = string.Format("UPDATE RECETTES SET TITRE ='{0}', DIFFICULTE ='{1}', TEMPS_PREPARATION ='{2}'," + "NOMBRE_PERSONNES ='{3}', TYPE_CALORIQUE ='{4}', DESCRIPTIF ='{5}'" + "FROM RECETTES ", nom, diff, tmp_prepa, nb_personne, calorie, desc); int test = dal.update(dtTable, update); return test; }
please help !![]()
Partager