Bonjour, j'ai créer cette fonction qui a pour but de retourner un Dataview a partir d'une requêtes. J'ai l'impression d'en avoir un peu trop mit pour rien. Qu'en penser vous? Aurais-je pu faire dans le plus simple... D’ailleurs cette fonction ne me permet même pas de faire du multi table.

Merci de me donner votre point de vue.

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
Public Function selecttable(ByVal Table As String, _
                                ByVal Selection As String, _
                                Optional ByVal whereSql As String = Nothing, _
                                Optional ByVal orderBySql As String = Nothing) As DataView
 
        Dim daTable As New OleDbDataAdapter
        Dim dtTable As New DataTable
        Dim sqlstring As String = "SELECT " & Selection & " FROM " & Table
 
        If Not (whereSql Is Nothing) AndAlso 0 < whereSql.Length Then
            sqlstring += " WHERE " + whereSql
        End If
 
        If Not (orderBySql Is Nothing) AndAlso 0 < orderBySql.Length Then
            sqlstring += " ORDER BY " + orderBySql
        End If
 
        Using connection As New OleDbConnection(m_ConnectionString)
 
            ' Insert une nouvelle ligne dans la table.
            Dim command As New OleDbCommand(sqlstring, connection)
 
            ' Open the connection and execute the insert command.
            Try
                connection.Open()
                command.ExecuteNonQuery()
 
                daTable.SelectCommand = command
                daTable.Fill(dtTable)
 
                Return New DataView(dtTable)
 
            Catch ex As Exception
                Console.WriteLine(ex.Message)
                Return Nothing
 
            End Try
        End Using
    End Function