• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

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

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;

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

          dcStates.Open();

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

          ddlTest.DataSource = drStates;
          ddlTest.DataBind();
          ddlTest.Items.Insert(0, new ListItem("Select State"));
     }
     catch (Exception exc)
     {
          throw exc;
     }
     finally
     {
          dcStates.Close();
     }
}

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 :)
0
Dwalden
Asked:
Dwalden
1 Solution
 
wiseguy_2112Commented:
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";
0
 
DwaldenAuthor Commented:
Got it in one. I wasn't setting the DataTextField and DataValueField.

Thanks a lot
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now