Bonjour
Dans le code suivant, je fais la recherche d'une valeur dans le champ sal1 de la table table_salaire et je la compare avec la valeur du textbox sal1.Text
Lorsque je trouve la ligne en question, je change cette valeur par une autre valeur lue dans un autre textbox nouveau_sal.Text
Au niveau de la ligneje recois le message suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part MyDataAdapter.Update(MyDataset, "table_salaire")
Avez-vous une idée ?Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information
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 Dim Myconnexion As SqlConnection Dim Mycommand As SqlCommand Dim MyDataAdapter As SqlDataAdapter Dim MyDataset As New DataSet() Dim strSql As String Dim MyDataTable As DataTable Dim MyDataRow As DataRow Dim RowNumber As Integer = 0 Dim MyConnexionString As String Dim MyCommandBuilder As SqlCommandBuilder = Nothing Try MyConnexionString = "Data Source=natahlie;Initial Catalog=Data_Base_salaire;Integrated Security=True" strSql = "SELECT sal1 FROM table_salaire" Myconnexion = New SqlConnection Myconnexion.ConnectionString = MyConnexionString Myconnexion.Open() Mycommand = New SqlCommand(strSql) MyDataAdapter = New SqlDataAdapter(Mycommand) Mycommand.Connection() = Myconnexion MyDataAdapter.Fill(MyDataset, "table_salaire") MyDataTable = MyDataset.Tables("table_salaire") RowNumber = MyDataTable.Rows.Count If MyDataTable.Rows.Count > 0 Then RowNumber = 0 While RowNumber <= MyDataTable.Rows.Count - 1 MyDataRow = MyDataset.Tables("table_salaire").Rows(RowNumber) If MyDataRow("sal1") = sal1.Text Then MyDataRow("sal1") = nouveau_sal.Text MyCommandBuilder = New SqlCommandBuilder(MyDataAdapter) MyDataAdapter.Update(MyDataset, "table_salaire") Exit While End If RowNumber = RowNumber + 1 End While Else MessageBox.Show("pas de résultat pour les données", "Infos", _ MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End If Catch ex As Exception MessageBox.Show(ex.Message) Finally If Not (Myconnexion Is Nothing) Then Myconnexion.Close() End Try
Partager