The multi-part identifier "System.Data.DataRowView" could not be bound

ado.net, c#, sql-server

Solution

This is due to loading second combobox while filling data in first combo. You can avoid this error by: 1. Use SelectionChangeCommitted event instead of SelectedIndexChanged event. Or 2. Detach selected index change event, populate combobox, attach event again as:

private void frm2_Load(object sender, EventArgs e)
{
   //Detach event
   comboBox1.SelectedIndexChanged -= comboBox1_SelectedIndexChanged;

    //Populate Combobox1
    SqlDataAdapter da = new SqlDataAdapter("SELECT CategoryID, Name FROM Categories", clsMain.con);
    DataSet ds = new DataSet();
    da.Fill(ds);
    comboBox1.DataSource = ds.Tables[0];
    comboBox1.DisplayMember = "Name";
    comboBox1.ValueMember = "CategoryID";

   //Attach event again
    comboBox1.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
}

Hopes this will help you.

Problem

I have a table that populate Combobox1 and Combobox1 should populate Combobox2 and this is where the problem is. That's the exception i'm getting The multi-part identifier "System.Data.DataRowView" could not be bound. Code : ``` private void frm2_Load(object sender, EventArgs e) { //Populate Combobox1 SqlDataAdapter da = new SqlDataAdapter("SELECT CategoryID, Name FROM Categories", clsMain.con); DataSet ds = new DataSet(); da.Fill(ds); comboBox1.DataSource = ds.Tables[0]; comboBox1.DisplayMember = "Name"; comboBox1.ValueMember = "CategoryID"; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { //populate Combobox2 SqlDataAdapter da = new SqlDataAdapter("SELECT SubCategoryID, Name FROM SubCategories WHERE CategoryID=" + comboBox1.SelectedValue, clsMain.con); DataSet ds = new DataSet(); da.Fill(ds); comboBox2.DataSource = ds.Tables[0]; comboBox2.DisplayMember = "Name"; comboBox2.ValueMember = "SubCategoryID"; } ```

Original source