在sql server 的表结构中设置 字段C的公式为  字段A*字段B,在.net中以dataGridView与该表绑定,但修改字段A或字段B时字段C的值不会立即更新,要保存后再次打开字段C的值才会更新,有什么办法让字段C的值立即更新呢?
先谢过!

解决方案 »

  1.   

    我不希望改一条纪录就保存,因为用户可能不保存当前修改,我的目的是当用户在dataGridview中修改字段A或字段B时,字段C的值立即被重算,而不用等到我下次再打开该表.
      

  2.   

    找到IDE成生的updateCommand的语句
    把C列的值(应该为@c)改为 @A*@B
      

  3.   

    可以在DataGridView的CellEndEdit事件下进行处理...判断如果当前的列是列A或者列B,更改列C的值...
      

  4.   

    sample example:private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
            {
                //假如列A和列B的索引分别为0和1,列C的索引是2
                if (e.ColumnIndex == 0 || e.ColumnIndex == 1)
                {
                    int valueA = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells[0].Value);
                    int valueB = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells[1].Value);
                    this.dataGridView1.Rows[e.RowIndex].Cells[2].Value = valueA * valueB;
                }
            }不知道是不是这意思?
      

  5.   

    谢谢liujia_0421(SnowLover) ,基本上是这个意思,只是想知道有没有更好的办法,比如有没有一个什么ReCompute()方法,因为表结构是用户自定义的,所以这样实现会很麻烦
      

  6.   

    就是说在dataGridview中根据表结构中字段C的公式重算一下字段C,而不是自己写:  this.dataGridView1.Rows[e.RowIndex].Cells[2].Value = valueA * valueB;
    ,因为公式是用户定义的
      

  7.   

    我试了,只有保存dataGridview所做修改,并再次fill 数据集,才可得到计算后的字段C,如果不提交dataGridview所做修改,就只能自己写代码来计算字段C,好象还没有什么好办法