Bonjour j'essaie de remplir une DropDownList avec le contenu d'une table SQL, mais je n'y arrive pas.
Voici mon code :
Pourriez-vous m'indiquer comment procéder?
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 SqlConnection myConnection = new SqlConnection(); myConnection.ConnectionString = "Data Source=PC-LAURENCE\\SQLEXPRESS; Initial Catalog=Librarie; Integrated Security=True;"; myConnection.Open(); // Requete SQL SqlCommand myCommande; myCommande = new SqlCommand("SELECT Titre, ISBN from Ouvrages", myConnection); SqlDataReader lecteur = myCommande.ExecuteReader(); if (IsPostBack == false) { Book[] books ; // Déclaration d'un tableau books de Type Book while (lecteur.Read()) { books = new Book (lecteur["Titre"].ToString(), lecteur["ISBN"].ToString()); DdlBooks.DataSource = books; DdlBooks.DataTextField = "BookTitle"; DdlBooks.DataValueField = "Isbn"; DdlBooks.DataBind(); } } lecteur.Close(); myConnection.Close();
Merci pour votre aide !
Partager