请问: private void Login_Load(object sender, EventArgs e)
{
string sql = "select ID = replace(ID,' ',''),部门名称 = replace(部门名称,' ','') from 组织机构表 where 上级部门ID=0";
DataSet ds = md.getDataSet(sql, "组织机构表");
this.comboBox1.DataSource = ds.Tables["组织机构表"];
this.comboBox1.DisplayMember = "部门名称";
this.comboBox1.ValueMember = "ID";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{ string sql = "select ID = replace(ID,' ',''),部门名称 = replace(部门名称,' ','') from 组织机构表 where 上级部门ID = " + comboBox1.SelectedValue.ToString() + "";
DataSet ds = md.getDataSet(sql, "组织机构表");
this.comboBox2.DataSource = ds.Tables["组织机构表"];
this.comboBox2.DisplayMember = "部门名称";
this.comboBox2.ValueMember = "ID";
}
执行后 出现 “无法绑定由多个部分组成的标识符 "System.Data.DataRowView"。“错误
应怎么解决?
谢谢!
{
string sql = "select ID = replace(ID,' ',''),部门名称 = replace(部门名称,' ','') from 组织机构表 where 上级部门ID=0";
DataSet ds = md.getDataSet(sql, "组织机构表");
this.comboBox1.DataSource = ds.Tables["组织机构表"];
this.comboBox1.DisplayMember = "部门名称";
this.comboBox1.ValueMember = "ID";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{ string sql = "select ID = replace(ID,' ',''),部门名称 = replace(部门名称,' ','') from 组织机构表 where 上级部门ID = " + comboBox1.SelectedValue.ToString() + "";
DataSet ds = md.getDataSet(sql, "组织机构表");
this.comboBox2.DataSource = ds.Tables["组织机构表"];
this.comboBox2.DisplayMember = "部门名称";
this.comboBox2.ValueMember = "ID";
}
执行后 出现 “无法绑定由多个部分组成的标识符 "System.Data.DataRowView"。“错误
应怎么解决?
谢谢!
为什么喜欢用中文表示字段名啊
string sql = "select replace(ID,' ','') as ID , replace(部门名称,' ','') as 部门名称 from 组织机构表 where 上级部门ID = " + comboBox1.SelectedValue.ToString() + "";
Sql语句没有错误
在 Form_Load 事件里填充 DataTable 数据
利用 DataTable.Select 方法获取满足条件的 DataRow[] 作为绑定的源就可以了
把ID这个列去掉.试下.
(没试过,个人觉得,你这查出来是两个字段,绑到ComBox有错.因为你comboBox1绑定用ID=0条件,查出来没数据,所以不会出错.)