Bonjour à tous,

voila mon petit problème :

J'ai une application VB6 qui travail sur une base de donnée. Jusque là tout va bien, les temps d'accès sont rapide.
Là où cela ce corse c'est en passant le programme VB6 en VB.NET. En effet, j'utilise MySQLClient pour travailler sur la base
de données. Malheureusement les temps d'accès sont très long par rapport à vb6.

Dans le doute je vous met la méthode que j'ai développé :
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    ''' <summary>
    ''' Generics method to get information from a db table.
    ''' </summary>
    ''' <param name="tableName">Table's name to look for.</param>
    ''' <param name="fieldName">array of fields/field to retrieve information.</param>
    ''' <param name="filtre">Specific clause of research</param>
    ''' <returns>return a 2 dimension array in case of success or nothing in case of fail.</returns>
    ''' <remarks>1st dimension references a record. 2nd dimension references the(all) value(s) for the researched field(s).</remarks>
    Public Function [Select](ByVal tableName As String, Optional ByRef fieldName() As String = Nothing, Optional ByVal filtre As String = "") As String(,)
        Dim cmd As MySqlCommand
        Dim RowCount As Integer
        Dim sqlQuery As StringBuilder = New StringBuilder()
        Dim sqlQueryRow As StringBuilder = New StringBuilder("SELECT COUNT(*) FROM " & tableName)
        Dim fieldSize As Integer = 0
        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim value(,) As String = Nothing
 
        If Not String.IsNullOrEmpty(tableName) Then
            If fieldName Is Nothing Then
                fieldSize = CountCol(tableName) - 1
                sqlQuery.Append(String.Format("SELECT * FROM {0}", tableName))
            Else
                fieldSize = fieldName.Length - 1
                sqlQuery.Append("SELECT ")
 
                If fieldSize = 0 Then
                    sqlQuery.Append(String.Format("{0} FROM {1}", fieldName(0), tableName))
                Else
                    For i = 0 To fieldSize
                        If i = fieldSize Then
                            sqlQuery.Append(String.Format(" {0} ", fieldName(i)))
                        Else
                            sqlQuery.Append(String.Format(" {0},", fieldName(i)))
                        End If
                    Next
 
                    sqlQuery.Append(String.Format("FROM {0}", tableName))
                End If
            End If
 
            If filtre.StartsWith("ORDER") Then
                sqlQuery.Append(String.Format(" {0}", filtre))
                sqlQueryRow.Append(String.Format(" {0}", filtre))
            ElseIf Not String.IsNullOrEmpty(filtre) Then
                sqlQuery.Append(String.Format(" WHERE {0}", filtre))
                sqlQueryRow.Append(String.Format(" WHERE {0}", filtre))
            End If
 
            Try
                If OpenConnexion() Then
                    cmd = New MySqlCommand(sqlQueryRow.ToString(), _cnx)
                    RowCount = CInt(cmd.ExecuteScalar())
                End If
            Catch ex As Exception
            Finally
                CloseConnexion()
            End Try
 
            Try
                If OpenConnexion() Then
                    cmd = New MySqlCommand(sqlQuery.ToString(), _cnx)
                    _dataReader = cmd.ExecuteReader()
 
                    Dim val(RowCount - 1, fieldSize) As String '= New String
 
                    If _dataReader.HasRows Then
                        i = 0
                        Do While _dataReader.Read()
                            For j = 0 To _dataReader.FieldCount - 1
                                val(i, j) = _dataReader.Item(j).ToString()
                            Next
                            i += 1
                        Loop
                    End If
 
                    If val.Length > 0 Then
                        value = val
                    End If
                End If
            Catch ex As MySqlException
                'Exception lors de la requete
            Catch ex3 As IndexOutOfRangeException
                'depassement capacité tableau
            Catch ex2 As Exception
                'erreur inattendue
            Finally
                CloseConnexion()
            End Try
        End If
 
        Return value
    End Function
Avez vous une idée du pourquoi du comment ?
Je vous remercie d'avance.