Solved

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

Posted on 2004-08-10
3
302 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

24 Experts available now in Live!

Get 1:1 Help Now