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
|
Dim sql As Text.StringBuilder = New Text.StringBuilder("")
sql.Append("SELECT * FROM maTable")
If _clauseWhere = "" Then
'On ne complètepas la requête
Else
sql.Append(_clauseWhere)
End If 'Fin si clause WHERE vide
'Connexion à la BDD
Dim strConnexion As String = connectionString
Dim oConnexion As New System.Data.SqlClient.SqlConnection(strConnexion)
Dim openConnectionError As Boolean = False
Try
oConnexion.Open()
Catch ex As Exception
openConnectionError = True
End Try
'Si l'ouverture de la connexion s'est bien passée on exécute la requête
If Not openConnectionError Then
Dim oCommand As New System.Data.SqlClient.SqlCommand(sql.ToString)
oCommand.Connection = oConnexion
Dim oDataAdapter As New System.Data.SqlClient.SqlDataAdapter(oCommand)
Dim dtResult As New System.Data.DataTable()
Try
oDataAdapter.Fill(dtResult)
Catch ex As Exception
Finally
oConnexion.Close()
oCommand.Dispose()
End Try
'On renseigne les propriétées de l'objet l'objet
If dtResult.Rows.Count = 0 Then
distributeurs = Nothing
Else
For Each row As Data.DataRow In dtResult.Rows
distributeurs.Add(New AjaxControlToolkit.CascadingDropDownNameValue(row("libelle"), row("id_distributeur")))
Next
End If 'Fin si dataTable non vide
dtResult.Dispose()
End If 'Fin si connection OK |
Partager