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
| Public Function DoSelect(ByVal table As ArrayList, ByVal fields As ArrayList, ByVal criterias As ArrayList, ByVal distinct As Boolean, ByVal order As ArrayList) As DataSet
'each item of fields must be structured like "tableName.fieldName"
'criterias must be structured like this : <key,value> where key is the fieldname and the operator
'example : < "client.NIDCLIENT" = ; 0 > or < "contact.CNOM" = ; "arnaud" >
Dim sql As String
Try
If Not da Is Nothing Then
da.Dispose()
da = New Advantage.Data.Provider.AdsDataAdapter
Else
da = New Advantage.Data.Provider.AdsDataAdapter
End If
If distinct Then
sql = "select distinct "
Else
sql = "select "
End If
If Not (fields Is Nothing) Then
For Each elem As String In fields
sql = sql + elem + ", "
Next
Else
sql = sql + "* "
End If
sql = sql.TrimEnd(", ".ToCharArray) + " from "
For Each elem As String In table
sql = sql + elem + ", "
Next
sql = sql.TrimEnd(", ".ToCharArray) + " where "
If Not (criterias Is Nothing) Then
For Each elem As String In criterias
sql = sql + elem + " AND "
Next
If sql.EndsWith(" AND ") Then
sql = sql.Substring(0, sql.Length - 5)
End If
End If
If sql.EndsWith(" where ") Then
sql = sql.Substring(0, sql.Length - 7)
End If
If Not (order Is Nothing) Then
sql = sql + " order by "
For Each elem As String In order
sql = sql + elem + ","
Next
sql = sql.TrimEnd(",")
If sql.EndsWith(" order by ") Then
sql = sql.Substring(0, sql.Length - 10)
End If
End If
'MsgBox(sql)
cmd.CommandText = sql
da.SelectCommand = cmd
ds.Reset()
da.Fill(ds)
Catch ex As Exception
MsgBox(ex.Message)
End Try
Return ds
End Function |
Partager