Solved

populate dropdownlist with datareader

Posted on 2006-06-29
1
1,225 Views
Last Modified: 2012-08-14
Hi there,

I am having a problem with populating a dropdownlist. The code is as follows :


            myConnection = New SqlConnection ("server=slserver;uid=;pwd=;database=meta_dev")
            SQL$ = ""
            SQL$ = SQL$ & " select      glpd_key      "
            SQL$ = SQL$ & " from        gl_period   "
            myConnection.Open()
            myCommand = New SqlCommand(SQL$, myConnection)
            myDataReader = myCommand.ExecuteReader()
            Me.ddl_glperiod.DataSource = myDataReader
            Me.ddl_glperiod.DataBind()
            'close connection to item_map_gl
            myConnection.Close()

        ddl_glperiod.SelectedIndex = 15
           
When the page load - it populates the dropdownlist with System.Data.Com.... If i debug the code, there is no errors.

Can someone help please ....

Thanks
0
Comment
Question by:venterm
1 Comment
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 17010109
Hi venterm,

You need to specify the DataTextField and DataValueField properties so that the dropdown knows what data to display:

            myConnection = New SqlConnection ("server=slserver;uid=;pwd=;database=meta_dev")
            SQL$ = ""
            SQL$ = SQL$ & " select      glpd_key     "
            SQL$ = SQL$ & " from        gl_period   "
            myConnection.Open()
            myCommand = New SqlCommand(SQL$, myConnection)
            myDataReader = myCommand.ExecuteReader()
            Me.ddl_glperiod.DataSource = myDataReader
            ddl_glPeriod.DataTextField = "glpd_key"
            ddl_glPeriod.DataValueField = "glpd_key"
            Me.ddl_glperiod.DataBind()
            'close connection to item_map_gl
            myConnection.Close()

        ddl_glperiod.SelectedIndex = 15

Tim Cottee
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now