如何错误无法绑定到新的显示成员。参数名称:newDisplayMember

时间:2014-05-20 11:55:48

标签: c# combobox

这是我的代码,当调用此函数时返回错误:

Cannot bind to the new display member.Parameter name: newDisplayMember

代码:

public void FillDrpKala()
    {
        string SQL = "SELECT [kID],[kName] FROM tblKala ORDER BY kName";
        DataSet ds = new DataSet();
        using (SqlConnection cn = new SqlConnection(objCon.StrCon))
        {
            using (SqlDataAdapter adapter = new SqlDataAdapter(SQL, cn))
            {
                cn.Open();

                try
                {
                    adapter.Fill(ds);
                }
                catch (SqlException e)
                {

                    MessageBox.Show("There was an error accessing your data of Kala. DETAIL: " + e.ToString());
                }
            }
        }
        cmbKala.DataSource = ds.Tables[0];
        cmbKala.DisplayMember = "mName";
        cmbKala.ValueMember = "mID";
    }

1 个答案:

答案 0 :(得分:2)

您的列名已混淆。

而不是

cmbKala.DisplayMember = "mName";
cmbKala.ValueMember = "mID";

试试这个:

cmbKala.DisplayMember = "kName";
cmbKala.ValueMember = "kID";