Adding int value from database to dropdownlist

  • Thread starter Thread starter djozy
  • Start date Start date
D

djozy

Please,
I am using SqlDatareader in C# and when I want to put int
value ,that is get by datareader, to dropdown list I get
this error:
An invalid data source is being used for idlist. A valid
data source must implement either IListSource or
IEnumerable.

Source Error:

SqlDataReader myReader = myCommand.ExecuteReader();
myReader.Read ();
this.dropdownlist.DataSource =myReader.GetValue(0);
this.dropdownlist.DataBind();
 
Hi

Try this:
SqlDataReader myReader = myCommand.ExecuteReader();
myReader.Read ();
this.dropdownlist.DataSource =myReader.GetValue(0);
this.dropdownlist.DataTextField="THE NAME OF THE TEXT FIELD"
this.dropdownlist.DataValueField="THE NAME OF THE VALUE FIELD";
this.dropdownlist.DataBind();

Hope this help,
 
Back
Top