当我在我的机器上运行我的程序时它工作得很好但是当我从其他机器运行代码时,我得到一个错误,表示"无法绑定到新的显示成员"?我只是不明白为什么?这是我的代码。
private DataTable effectivity, filesTable, cgmFiles;
private void FillEffectivity()
{
cbEffectivity.ComboBox.DataSource = null;
effectivity = FillDataTable("SELECT * FROM Projects ORDER BY Project ASC");
cbEffectivity.ComboBox.DataSource = effectivity;
cbEffectivity.ComboBox.DisplayMember = "project";
cbEffectivity.ComboBox.ValueMember = "RecNo";
}
private DataTable FillTable(string sql)
{
DataTable table = new DataTable();
try
{
using (OleDbDataAdapter da = new OleDbDataAdapter(sql, cn))
{
da.Fill(table);
}
}
catch (Exception ex)
{
if (ex.Message == "Not a valid password.")
{
SetPassword();
return FillTable(sql);
}
return new DataTable();
}
finally
{
cn.Close();
}
return table;
}
答案 0 :(得分:0)
您的查询中似乎有问题,而不是effectivity = FillDataTable("SELECT * FROM Projects ORDER BY Project ASC");
尝试FillDataTable("SELECT * FROM Projects ORDER BY project ASC");
同时建议不要使用*而选择它会影响性能。 试试这个
FillDataTable("SELECT project FROM Projects ORDER BY project ASC");