Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:07:41+00:00 2026-05-29T07:07:41+00:00

I cannot bind data to a Dropdown List .. Can any one explain me

  • 0

I cannot bind data to a Dropdown List.. Can any one explain me why?
Error is : 'System.Data.DataRowView' does not contain a property with the name '_DeptID'.
my code is:

public class ClassDataManagement
{
    public DataTable BindDropDownList(string Sql, DropDownList DropDownList)
    {
        SqlConnection cn = new SqlConnection(@"Data Source=ABID-PC;Initial Catalog=_uniManagement;Integrated Security=True");
        SqlCommand cmd = new SqlCommand(Sql, cn);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        if (dt.Rows.Count == 0)
        {

        }
        else
        {
            DropDownList.DataTextField = "Name";
            DropDownList.DataValueField = "_DeptID";
            DropDownList.DataSource = dt.DefaultView;
            DropDownList.DataBind();
        }
        return dt;
    }

}
protected void Page_Load(object sender, EventArgs e)
{
    ClassDataManagement dm = new ClassDataManagement();
    dm.BindDropDownList("select _Program.Name from _program,_Department where _program._Deptid = _department._DeptId", DropDownListProgram);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:07:42+00:00Added an answer on May 29, 2026 at 7:07 am
    1. The column _Dept is missing in your select statement
    2. Disposing of the objects is missing. So you can perform it in two ways

      (a) Manually disposing

      (b) Using Statement


    public class ClassDataManagement
    {
        public DataTable BindDropDownList(string Sql, DropDownList DropDownList)
        {
            using (SqlConnection cn = new SqlConnection(@"Data Source=ABID-PC;Initial Catalog=_uniManagement;Integrated Security=True"))
            {
                using (SqlCommand cmd = new SqlCommand(Sql, cn))
                {
                    using(SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        using (DataTable dt = new DataTable())
                        {
                            da.Fill(dt);
                            DropDownList.DataTextField = "Name";
                            DropDownList.DataValueField = "_Deptid";
                            DropDownList.DataSource = dt.DefaultView;
                            DropDownList.DataBind();
                            return dt;
                        }
                    }
                }
            }
        }
    
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ClassDataManagement dm = new ClassDataManagement();
        dm.BindDropDownList("select _Program.Name, _program._Deptid from _program,_Department "
            + "where _program._Deptid = _department._DeptId", DropDownListProgram);
    
    }
    

    EDIT – 1

    Adding the Using Statement for SqlDataAdapter as well

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I get jaxb to bind to my Vector? I cannot seem to
I am new to KnockOut JS and I cannot find the reason for data-bind
I'm not able to bind events to a list that is generated by jQuery.
I am getting user list using Membership.GetAllUsers() function. And I bind this data in
I really want to know why in the first case I can bind data
I tried to bind data to a template created using GroovyPagesTemplateEngine, but cannot. Here
I cannot get a two-way bind in WPF to work. I have a string
Cannot dump Stack Overflow XML file into SQL Server 2008. Could you please explain
Cannot find any example on Google.
I cannot understand the Oracle documentation. :-( Does anybody know how to fetch multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.