- Imports System.Data.SqlClient
-
- 'voila comment on l'appel
- Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
-
- ChoixPoste.Text = "choisir le poste"
- Dim requete1 As String = "select tutu,tata from titi"
-
- If Not IsPostBack Then
- init_DropDownList("nom base de données", requete1, DropDownList1, "champ à afficher ici tutu", "la clé qui lui correspond disons tata")
- DropDownList1.Items.Insert(0, "<--------------selectionner-------------->")
- End If
-
- End Sub
-
- 'voila la procédure qui le gère
- Sub init_DropDownList(ByVal BDD As String, ByVal requete As String, ByRef ld As DropDownList, ByVal TextField As String, ByVal ValueField As String)
-
- 'connection a la base de données
- MyConnection = New SqlConnection
- MyConnection.ConnectionString = "server='nom machine';database='nom base de données';user id='user';password='mot de passe';Trusted_Connection=true"
-
- MyConnection.Open()
-
- Dim MyCommand As New SqlDataAdapter(requete, MyConnection)
-
- Dim DS As DataSet = New DataSet
-
- MyCommand.Fill(DS, "temp")
-
- ld.DataSource = DS.Tables("temp").DefaultView
-
- ld.DataTextField = TextField
-
- ld.DataValueField = ValueField
-
- ld.DataBind()
-
- MyConnection.Close()
-
- End Sub
Imports System.Data.SqlClient
'voila comment on l'appel
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ChoixPoste.Text = "choisir le poste"
Dim requete1 As String = "select tutu,tata from titi"
If Not IsPostBack Then
init_DropDownList("nom base de données", requete1, DropDownList1, "champ à afficher ici tutu", "la clé qui lui correspond disons tata")
DropDownList1.Items.Insert(0, "<--------------selectionner-------------->")
End If
End Sub
'voila la procédure qui le gère
Sub init_DropDownList(ByVal BDD As String, ByVal requete As String, ByRef ld As DropDownList, ByVal TextField As String, ByVal ValueField As String)
'connection a la base de données
MyConnection = New SqlConnection
MyConnection.ConnectionString = "server='nom machine';database='nom base de données';user id='user';password='mot de passe';Trusted_Connection=true"
MyConnection.Open()
Dim MyCommand As New SqlDataAdapter(requete, MyConnection)
Dim DS As DataSet = New DataSet
MyCommand.Fill(DS, "temp")
ld.DataSource = DS.Tables("temp").DefaultView
ld.DataTextField = TextField
ld.DataValueField = ValueField
ld.DataBind()
MyConnection.Close()
End Sub