DataBinding: 'System.Char' does not contain a property with the name

16,811

The problem is that you bind a string to your DataSource

ddlEmployee.DataSource = DSEmployee.Tables[0].DefaultView.ToString();

And a string don't have a property APPRAISER_ID.

select employee_id,appraiser_id from kirti_pms_reporting where appraiser_id='" + 
varAppraiserId.ToString() + "'";

Is not a good idea because you could run into SqlInjection.

Share:
16,811

Related videos on Youtube

itzArun
Author by

itzArun

Updated on June 04, 2022

Comments

  • itzArun
    itzArun almost 2 years

    I searched throughout the website for the error

    I am getting this error while binding a dropdown list.

    DataBinding: 'System.Char' does not contain a property with the name "APPRAISER_ID"

    Here's my code:

    DataSet DSEmployee = new DataSet();
    DSEmployee = ws_service.GetReportingDtl(user);
    ddlEmployee.DataTextField = "APPRAISER_ID";
    ddlEmployee.DataValueField = "APPRAISER_ID";
    ddlEmployee.DataSource = DSEmployee.Tables[0].DefaultView.ToString();
    ddlEmployee.DataBind();
    

    And in my webservice.

    string strQ = "select employee_id,appraiser_id from kirti_pms_reporting where appraiser_id='" + varAppraiserId.ToString() + "'";
    

    My Inline code for dropdown list is

    <asp:DropDownList ID="ddlEmployee" runat="server" AutoPostBack="true"  CssClass="vlu">
    

    What I missed here? The same code works fine in another aspx page.

    • SLaks
      SLaks over 12 years
      You have a SQL injection vulnerability.
  • Hans Kesting
    Hans Kesting over 12 years
    Note: the reason for the 'System.Char' error message is that the datasource should be Enumerable. That String is enumerable: it's a list of chars. And a Char doesn't have that 'Appraiser_id'.
  • dknaack
    dknaack over 12 years
    @HansKesting A String is not just a list of chars, or array of chars, in .NET.
  • Hans Kesting
    Hans Kesting over 12 years
    @dknaack - no, a string is not a list of chars, but it is an IEnumerable<Char>, which is what counts here.
  • dknaack
    dknaack over 12 years
    @HansKesting Yes System.String implements IEnumerable<char>, but other interfaces too. right
  • SearchForKnowledge
    SearchForKnowledge over 9 years