trouble while filling an dropDownListBox

  • Thread starter Thread starter Alexandre Jaquet
  • Start date Start date
A

Alexandre Jaquet

hi withe the following code I got some strange result
when the page load it's only fill one element
could anyone tell me why thx

private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
this.sqlConnection1 = new SqlConnection ("server=HEWLETT-
IPODDL1\\SQLSERVEUR;Database=KEYLAB;user
id=sa;password=pwd");

this.sqlConnection1.Open ();
SqlDataReader reader;
this.sqlCommandGetLab = new SqlCommand ("SELECT
DESIGNATION_LABORATOIRE FROM laboratoire",

this.sqlConnection1);
reader = this.sqlCommandGetLab.ExecuteReader ();
reader.Read ();
this.dropDownListLab.DataSource = reader.GetString(0);
Page.DataBind();
this.sqlConnection1.Close ();
}

}
 
Hi

You are reading only one row and assigning it to the list box.
Thats why you are getting only one item.

Try this:

Do While myReader.Read()
// add myReader.GetString(0)) to list box items collection.
Loop
 
Back
Top