这是我的代码,当调用此函数时返回错误:
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";
}
答案 0 :(得分:2)
您的列名已混淆。
而不是
cmbKala.DisplayMember = "mName";
cmbKala.ValueMember = "mID";
试试这个:
cmbKala.DisplayMember = "kName";
cmbKala.ValueMember = "kID";