Solved

Combobox displays wrong info: "System.data.common.dbdatarecord

Posted on 2004-08-10
3
307 Views
Last Modified: 2008-02-01
My Combo box is not displaying the contents of my table "tblcntry" it keeps displaying
Combobox displays wrong info: "System.data.common.dbdatarecord

can anyone help me correct this?

Thank you

Ted


============ CODE ================

Public Class TestDropdown
    Inherits System.Web.UI.Page

    Public MyConnect As SqlClient.SqlConnection = New SqlClient.SqlConnection(ConfigurationSettings.AppSettings("SQLDB_Test"))
    Public MyCommandCMBCountry As SqlClient.SqlCommand = New SqlClient.SqlCommand("SELECT Cntry FROM tblCntry ORDER BY Cntry", MyConnect)
    Public MyReaderCMBCountry As SqlClient.SqlDataReader
    Protected WithEvents cmbCountry As System.Web.UI.WebControls.DropDownList

    Public MyCommand As SqlClient.SqlCommand

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        MyConnect.Open()
        MyReaderCMBCountry = MyCommandCMBCountry.ExecuteReader(CommandBehavior.CloseConnection)
        cmbCountry.DataSource = MyReaderCMBCountry
        cmbCountry.DataBind()
        MyReaderCMBCountry.Close()
        MyConnect.Close()
    End Sub

End Class
0
Comment
Question by:tcalbaz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
daffodils earned 250 total points
ID: 11766497
You need to set the

"DataTextField" to the column name you want to display on the combo box.
"DataValueField" to the column name you want to retrieve as value.

Lets say you have a Customer table,
Setting "DataTextField" to the column "Customer ID" will display all customer IDs in the combo box.
Setting "DataValueField" to the column "Customer Name" will retrieve the Customer Name as the SelectedValue corresponding to the Customer ID selected in the combobox.

DataTextField - Gets or sets the field of the data source that provides the text content of the list items.
DataValueField - Gets or sets the field of the data source that provides the value of each list item.
0
 
LVL 8

Expert Comment

by:daffodils
ID: 11766556
A mistake in the exxample above..

Setting "DataTextField" to the column "Customer ID" will display all customer IDs in the combo box.

Setting "DataValueField" to the column "Customer Name" will retrieve the Customer Name as the <u>"SelectedItem.Value"</u> property of the the CustomerID selected in the combobox.
 
 
 

0
 
LVL 1

Author Comment

by:tcalbaz
ID: 11766862
BINGO!

Thank you daffodils !

Ted
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

733 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