表1: 生成DataSet1.table["contury"]
no    name    id_typename    rm  nn_type(此列为其它表关联过来的)
01    中国      1                  共产
02    美国      2                  资产
03    法国      3                  难名
表2:生成DataSet1.table["type"]
id_type    nn_type
1          共产
2          资本
3          难名=================================
现在有一个ComboBox(cmbType):  绑定到 table["type"](在属性中设定)
    cmbType.datasource=dataSet1;
    cmbType.displaymember=nn_type;
    cmbType.Valuemember=id_type
===================================
代码中帮定到DataSet1.table["contury"]:
this.cmbType.DataBindings.Add(new Binding("Text", DataSet1, "NN_TYPENAME"));运行均能正常显示现在问题是:当我改变cmbType的内容时,保存到数据库不能成功! private void cmbType_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.dsMaster1.Tables["contury"].Rows[this.bindingSource1.Position]["id_typename"] = this.cmbType.SelectedValue;
        }
发现这个方法被执行了4次,而我只不过是选了其中的一项.
最后值又变回没改之前了..... 

解决方案 »

  1.   


    private   void   cmbType_SelectedIndexChanged(object   sender,   EventArgs   e) 
     { 
        if(this.cmbType.SelectedIndex!=0)
          {        this.dsMaster1.Tables["contury"].Rows[this.bindingSource1.Position]["id_typename"]       =        this.cmbType.SelectedValue.ToString().Trim(); 
            } 
    }
    试试行不!
      

  2.   

    你ISpostBack里面设置了什么吗?
      

  3.   

    如果是winform的话将他赋个直给变量,也取不出来吗?