Solved

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Master Content Pages, WebForms, and Session Variables 1 43
Gridview selected row 9 44
ASP.NET MVC 2 31
Problem to refer to value 8 45
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

786 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