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
|
Public Function Access(ByVal RequeteSQL As String, ByVal Table As String, ByRef TableObject(,) As Object) As DataSet
Dim MyAdapter As OleDbDataAdapter = New OleDbDataAdapter(RequeteSQL, MyConnection)
Dim i As Integer
For i = 0 To TableObject.GetUpperBound(0)
MyAdapter.SelectCommand.Parameters.Add(TableObject(i, 0), TableObject(i, 1)).Value = TableObject(i, 2)
Next
Try
MyDataSetTemp.Clear()
MyAdapter.Fill(MyDataSetTemp, Table)
'A ce niveau les données résultantes de la requete se trouvent dans => MyDataSet.Tables(0)
Catch ex As Exception
MessageBox.Show("Failed to connect to database! " & ex.Message)
End Try
Return MyDataSetTemp
End Function
Private Sub main()
'...
Dim TempDataTable As DataTable
Dim TableObject(1, 2) As Object
'...
TableObject(0, 0) = "@nom"
TableObject(0, 1) = OleDbType.VarChar
TableObject(0, 2) = ComboBox1.Text
TableObject(1, 0) = "@prenom"
TableObject(2, 1) = OleDbType.VarChar
TableObject(3, 2) = ComboBox2.Text
TempDataTable = Access("SELECT nom, prenom FROM TaTable WHERE nom = ? AND prenom = ?", "TaTable", TableObject).Tables("TaTable")
If TempDataTable.Rows.Count > 1 Then
MsgBox("Il y a des homonymes")
End If
'...
End Sub |
Partager