I am trying to populate a drop downlist on my page with data in flightnum from the table Air_Flight, my dropdownlist keeps having System.Data.Datarow in the dropdownlist. Im pretty sure im one line of code away from getting the actual values in the dropdownlist, I am just not sure which line of code it is. Also the dropdownlist sees how many records are in the db. For instance if i have the flight numbers '123' , '987', '487' it will have 3 System.Data.Datarow line in the dropdownlist and if I had another flight_num it will then have 4 System.Data.Datarow in the dropdownlist.

sql = "Select flightnum from Air_flight"
        ddlflightnum.DataSource = objdb.getDataSet(sql)

Any help is appreciated!

Please Delete this thread I figured it out I needed the line of code

ddlflightnum.DataValueField = "flightnum"

Yup, you cannot populate a DropDownList like that. Code for that is as follows:

Dim conn As New SqlConnection( connection )
Dim cmdSelect As New SqlCommand( ""Select flightnum from Air_flight", conn )
Dim dtrReader As SqlDataReader


  dtrReader = cmdSelect.ExecuteReader()

  if dtrReader.HasRows then
    ddlflightnum.DataSource = dtrReader
    ddlflightnum.DataValueField = "flightnum"
    ddlflightnum.DataTextField = "flightnum"
  end if

End Try

Now if you do not specify DataTextField, it will default to the DataValueField.

You can populate it through a dataset how you were as well, but I would try to steer you away from datasets as it takes up a lot of resources and the above code is much more efficient.

hi firebirds98,
You can populate DropDownlList from Sql database as follows.

datareader_object = connection_object.executequery("SELECT city_name from City")
While dr.Read
End While

Hope this will help you.
Thanks & Regards

Please Delete this thread I figured it out I needed the line of code

ddlflightnum.DataValueField = "flightnum"

Delete? you should mark it as solved since you've got the right thing

This thread was from 2008 and was only resurrected by someone promoting their blog. That post has been deleted and I am closing this thread to prevent any further confusion.

This article has been dead for over six months. Start a new discussion instead.