DropDownList control filled with "System.Data.Common.DbDataRecord" on  Page_Load

Posted on 2003-02-26
Medium Priority
Last Modified: 2010-04-15
Howdy everyone.
What I'm trying to do is populate a DropDownList control in a web form with values from an MS Access database when the webform loads. When I browse the page, all the items in the control say "System.Data.Common.DbDataRecord".

In the Access database is the table "tblStates". This table has 2 fields only:
ID - an autonumber set as the key
States - a text field containing the states in the US.

Here is the code from the Page_Load event:

private void Page_Load(object sender, System.EventArgs e)
     string sql = @"SELECT ID, States from tblStates ORDER BY ID";
     string conStr =@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\databases\cyberslate.mdb;Persist Security Info=False";
     OleDbConnection dcStates = null;

          dcStates = new OleDbConnection(conStr);
          OleDbCommand cmd = new OleDbCommand(sql, dcStates);
          cmd.CommandTimeout = 30;


          OleDbDataReader drStates = cmd.ExecuteReader(CommandBehavior.CloseConnection);

          ddlTest.DataSource = drStates;
          ddlTest.Items.Insert(0, new ListItem("Select State"));
     catch (Exception exc)
          throw exc;

What am I doing wrong? BTW, I'm just now learning C# so I'm not using the toolbox in VS.NET until I have a firm grasp on doing things manually. I'd appreciate any help that doesn't suggest using the toolbox :)
Question by:Dwalden
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

Accepted Solution

wiseguy_2112 earned 200 total points
ID: 8034748
Do you have the DataTextField and DataValueField properties set?  You can do this in the properties page in VS.NET or you can do it in code...

ddlTest.DataTextField = "States";
ddlTest.DataValueField = "ID";

Author Comment

ID: 8035723
Got it in one. I wasn't setting the DataTextField and DataValueField.

Thanks a lot

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

752 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