Why am I getting System.Data.Common.DataRecordInternal on my drop down list>

Hi experts,
I'm trying to populate my drop down list internally in a couple different areas in my code and here is the code I'm using

Dim sconn As String
            sconn = System.Configuration.ConfigurationManager.ConnectionStrings("WebActivityConnectionString").ToString
            Dim myConnection As New SqlConnection
            myConnection.ConnectionString = sconn
            Dim myCommand As New SqlCommand
            myCommand.Connection = myConnection

            Try
                myConnection.Open()
                myCommand.Connection = myConnection
                myCommand.CommandText = "Select Statement_ID from Statement"
                myCommand.CommandType = CommandType.Text
                Dim reader As SqlDataReader = myCommand.ExecuteReader
                DDL_StatementID.DataSource = reader
                DDL_StatementID.DataBind()


When this happens all I get back are a bunch of System.Data.Common.DataRecordInternal?

Can anyone tell me what i'm doing wrong?
kpbaremAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Change your code to following

Dim sconn As String = System.Configuration.ConfigurationManager.ConnectionStrings("WebActivityConnectionString").ToString
Dim dbadp As New SqlDataAdapter("Select Statement_ID from Statement", sconn)
Dim dTable As New DataTable
dbadp.Fill(dTable)
dbadp.Dispose
DDL_StatementID.DisplayMember = "Statement_ID"
DDL_StatementID.ValueMember = "Statement_ID"
DDL_StatementID.DataSource = dTable
DDL_StatementID.DataBind()

Open in new window

0
 
kpbaremAuthor Commented:
You are awesome.  Thanks.  The only thing I found is that DDL_StatementID.DisplayMember and DDL_StatementID.ValueMember didn't work in my VBCode.

I changed it to DDL_StatementID.DataTextField and DDL_StatementID.DataValueField.
0
 
CodeCruiserCommented:
Yup confused it with winforms :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.