Methode renvoyant un array
bonjour,
Je souhaiterais récupérer dans un array les elements d'une table dans une bdd. mon 1er pb est que je n'arrive pas à trouver comment renvoyer le resultats (results()) sans passer par une variable publique....
De plus comment passer mes parametres (table et champ) dans ma requete ?
Code:
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
| Imports System.Data
Imports System.Data.OleDb
Friend Class FetchBdd
Protected Table As String
Protected Champ As String
Protected ParamConnexion As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & _
"LaboEMCSS_v2.0.mdb"
Public Function getResults(ByVal Table As String, ByVal Champ As String) As Array
Dim i As Integer
Dim results(100) As String
Dim MyConnexion As OleDbConnection = New OleDbConnection(ParamConnexion )
Dim Mycommand As OleDbCommand = MyConnexion.CreateCommand()
Mycommand.CommandText = "SELECT USER FROM USERS"
MyConnexion.Open()
Dim myReader As OleDbDataReader = Mycommand.ExecuteReader()
i = 0
Do While myReader.Read()
results(i) = myReader.GetString(0)
i = i + 1
Loop
myReader.Close()
MyConnexion.Close()
End Function
End Class |
j'instancie ensuite comme ceci :
Code:
1 2 3
|
Dim Req As New FetchBdd
Req.getResults("Users", "User") |
Merci d'avance.