Salut à tous, je voudrais pouvoir actualiser ma DB en envoyant un DataSet en parametres de la fonction; Ce DS contient la table, une fois modifiée par une autre fonction (pour ceux qui ont suivi les épisodes précédents, c'est un gridview qui actualisait le DS.
-> je voudrais récupérer sqlResponse, mais le système m'indique que le parametre de sortie est "NULL" après l'appel de mon DS.update(), donc j'en déduit, vu qu'en plus il n'a pas actualisé la bdd, qu'il n'a pas executé la procédure stoquée en question... pourquoi ?
-> J'ai tenté le code suivant, mais ca ne marche pas;
voici mon code :
please help me !
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 public string UpdateDB(DataSet ModifiedDS) { LOG("-------------------------------------------------------"); LOG("Call of WS UpdateDB(DataSet ModifiedDS) "); LOG("-------------------------------------------------------"); //LOG("" + ModifiedDS.GetXml() + ""); //LOG("-------------------------------------------------------"); try { SqlCommand SelectCommand = new SqlCommand(); SelectCommand.CommandType = CommandType.StoredProcedure; SelectCommand.CommandText = "SelectStoredProcedure"; SelectCommand.Connection = GetSQLConnection(); #region insert/update command SqlCommand SqlInsertUpdateCmde = new SqlCommand(); SqlInsertUpdateCmde.Connection = GetSQLConnection(ConnectionStrings.DirectoryBrowsingConnectionString.ToString()); SqlInsertUpdateCmde.CommandType = CommandType.StoredProcedure; SqlInsertUpdateCmde.CommandText = "UpdateStoredProcedure"; foreach (string ParamName in Enum.GetNames(typeof(DBstructure.TableGlobalSettings))) { SqlParameter sqlParameter = new SqlParameter(); sqlParameter.ParameterName = "@" + ParamName; sqlParameter.SourceColumn = ParamName; SqlInsertUpdateCmde.Parameters.Add(sqlParameter); } SqlParameter sqlResponse = new SqlParameter(); sqlResponse.Direction = ParameterDirection.Output; sqlResponse.Size = 100; sqlResponse.SqlDbType = SqlDbType.VarChar; SqlInsertUpdateCmde.Parameters.Add(sqlResponse); #endregion #region DataAdapter #region (comments) manual sql commands myDataAdapter.SelectCommand = SelectCommand; myDataAdapter.InsertCommand = SqlInsertUpdateCmde; myDataAdapter.UpdateCommand = SqlInsertUpdateCmde; #endregion #endregion int ChangeCount = 0; myDataAdapter.RowUpdating += new SqlRowUpdatingEventHandler(myDataAdapter_RowUpdating); myDataAdapter.RowUpdated += new SqlRowUpdatedEventHandler(myDataAdapter_RowUpdated); lock (objectToLock) { try { LOG("myDataAdapter_RowUpdated - starting"); ChangeCount = myDataAdapter.Update(ModifiedDS.Tables[DBstructure.DBTableNames.GlobalSettings.ToString()]); LOG("myDataAdapter_RowUpdated - ended -> @sqlResponse=" + sqlResponse.Value.ToString()); LOG("WS update function executed"); } catch (Exception exc) { LOG("myDataAdapter.Update -> " + exc.ToString()); } } return "Global settings have been updated : " + ChangeCount + " change" + (ChangeCount > 0 ? "s" : ""); } catch (Exception exc) { LOG("DataTable UpdateDB() -> " + exc.ToString()); return " WS UpdateDB -> " + exc.ToString(); } }
bye
Nico
Partager