pblm when bind data to dropdoen with datareader

Discussion in 'MCSE' started by srilakshmi, Jun 1, 2011.

  1. srilakshmi

    srilakshmi

    Joined:
    Jun 1, 2011
    Messages:
    1
    Likes Received:
    0
    hi ,

    when iam binding data to dropdown with datareader i use this code it is working properly
    while (dr.Read())
    {


    DropDownList1.DataSource = dr;

    DropDownList1.DataTextField = "countryname";
    DropDownList1.DataValueField = "countryname";

    DropDownList1.DataBind();


    }


    but i use like this iam getting error
    while (dr.Read())
    {


    DropDownList1.DataSource = dr;

    DropDownList1.DataTextField = dr[1].ToString();
    DropDownList1.DataValueField = dr[1].ToString();

    DropDownList1.DataBind();


    }

    error is :: DataBinding: 'System.Data.Common.DataRecordInternal' does not contain a property with the name 'INDIA'.
    i am not understanding why that error comes.
    if any one knows can u tell me pls
    ---thank you
     
    srilakshmi, Jun 1, 2011
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.