Bonjour
Je veux remplir un dataset à partir d'une table.
à l'exécution, un problème survient sur la ligne : myconnexion.open
Je travaille avec vb2008 et sql server 2005
Le contenu du code suivant se trouve dans un bouton click.
Merci de m'aider.
voici le code :
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 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 MsgBox("avant ouverture") Myconnexion.Open() MsgBox("apres ouverture") 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 RowNumber = RowNumber + 1 End If 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