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
| Dim Sql As String = "SELECT Nom, Ville Age From T_CLIENTS "
Dim P(3) As OleDbParameter = Nothing
Dim Nom() As String = {"toto"}, Ville As String = "Paris", Age As Integer = 26
Dim StrWhere As String = ""
If Nom.Count = 1 Then
P(0) = New OleDbParameter
StrWhere = "WHERE Nom=@Nom"
P(0).OleDbType = OleDbType.Char
P(0).ParameterName = "@Nom"
P(0).Size =50
P(0).Value = Nom(0)
Else
StrWhere = "WHERE Nom In("
For n As Integer = 0 To Nom.Count - 1
If n > 0 Then StrWhere += ","
StrWhere += " '" + Nom(n) + "'"
Next
StrWhere += ")"
End If
If Ville.Trim <> "" Then
P(1) = New OleDbParameter
If StrWhere.Trim = "" Then
StrWhere = "WHERE Ville=@Ville"
Else
StrWhere += " OR Ville=@Ville"
End If
End If
If Age.ToString.Trim <> "" Then
P(2) = New OleDbParameter
If StrWhere.Trim = "" Then
StrWhere = "WHERE Age=@Age"
Else
StrWhere += " OR Age=@Age"
End If
End If
Dim Cm As New OleDbCommand
For Each Prm As OleDbParameter In P
If Prm IsNot Nothing Then Cm.Parameters.Add(Prm)
Next |
Partager