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

Databind error on dropdown list

I am trying to display a field in a dropdown list (The field name is name)

My code:

private string conString = (@"Server=MASK\SQLEXPRESS;trusted_connection=yes;database=AdventureWorks");
//      private string conString = "user id=ASPNET;password=;" +
//          "initial catalog=Pubs;data source=localhost;" +
//          "Integrated Security=false;connect timeout=30;";

    private string selectStringA = "select * from Person.CountryRegion";
    private DataSet dsCountryRegion;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
          dpCountries.DataSource = "dsCountryRegion";
          dpCountries.DataTextField = "Name";

          SqlConnection sqlConnectA = new SqlConnection(conString);
          SqlDataAdapter sqladapterA = new SqlDataAdapter(selectStringA, sqlConnectA);
          dsCountryRegion = new DataSet();
          sqladapterA.Fill(dsCountryRegion, "CountryRegion");
          dpCountries.DataBind();          
         

The error:

Server Error in '/List_Bounds' Application.
DataBinding: 'System.Char' does not contain a property with the name 'Name'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Char' does not contain a property with the name 'Name'.

Source Error:

Line 33:           dsCountryRegion = new DataSet();
Line 34:           sqladapterA.Fill(dsCountryRegion, "CountryRegion");
Line 35:           dpCountries.DataBind();          
Line 36:          
Line 37:         }

WHAT AM I MISSING ?
0
allanmark
Asked:
allanmark
  • 3
  • 2
1 Solution
 
craskinCommented:
try this


          SqlConnection sqlConnectA = new SqlConnection(conString);
          SqlDataAdapter sqladapterA = new SqlDataAdapter(selectStringA, sqlConnectA);
          dsCountryRegion = new DataSet();
          sqladapterA.Fill(dsCountryRegion, "CountryRegion");

          dpCountries.DataSource = "dsCountryRegion";
          dpCountries.DataBind();  
          dpCountries.DataTextField = "Name";

also, "select * from Person.CountryRegion" doesn't make a lot of sense. is the table name countryregion, or is it person and you want to select only the countryregion column?
0
 
allanmarkAuthor Commented:
Hi!

SqlConnection sqlConnectA = new SqlConnection(conString);
          SqlDataAdapter sqladapterA = new SqlDataAdapter(selectStringA, sqlConnectA);          
          dsCountryRegion = new DataSet();
          sqladapterA.Fill(dsCountryRegion, "CountryRegion");
          dpCountries.DataSource = dsCountryRegion;   ==> DSCOUNTRYREGION SHOULDN'T HAVE BEEN IN
 
          dpCountries.DataTextField = "Name";      
          dpCountries.DataBind();
0
 
allanmarkAuthor Commented:
Hi

Sorry about previous comment attemp - I'm still new at this!!

Tried the code chnages - app now worked but was displaying D,S, C, O, U, N, T, R, I, E, S in the list  -  my error: dpCountries.DataSource = "dsCountryRegion" ==> DROP THE QUOTES !!!!

THANKS FOR THE HELP!!
0
 
craskinCommented:
ah yeh, sorry about that. i just copied and pasted your code and rearranged it. i didn't even so the quotes.
0
 
craskinCommented:
see not so.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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