灵魂-放水

为学日益,为道日损。

BlogJava 首页 新随笔 联系 聚合 管理
  296 Posts :: 10 Stories :: 274 Comments :: 0 Trackbacks
记录个自己的低级错误!!!!!!!!!!!!!!!!!

今天在对一个表进行删除,发现以下问题:

先附一段代码:(方便调试,加了些MessageBox.)
            string deleteID = this.costomerDataGrid[this.costomerDataGrid.CurrentRowIndex, 6].ToString();
            this.costomer_RecordTableAdapter.Fill(this.realEstatePDADataSet.Costomer_Record);
            MessageBox.Show("过滤前的dataView集合数:"+this.dataView2.Count.ToString());
            this.dataView2.RowFilter = "客户编号 = '" +deleteID+ "'";
            //this.dataView1.Sort = "来访时间";
            MessageBox.Show("过滤条件:" + deleteID);
            MessageBox.Show("过滤后的dataView集合数:"+this.dataView2.Count.ToString());
            this.costomer_RecordBindingSource.EndEdit();
            for (int i = 0; i < this.dataView2.Count; i++)
            {
                MessageBox.Show("删除第"+i+"条记录");
                this.costomer_RecordBindingSource.RemoveAt(i);
            }
            this.costomer_RecordTableAdapter.Update(this.realEstatePDADataSet.Costomer_Record);
            MessageBox.Show("删除成功!");

出现问题:表中的记录没被清除完全。仔细检查,发现Data.Count属性随着循环删除,每次比较 i < this.dataView2.Count,Count属性也是动态变化的。解决办法:
            string deleteID = this.costomerDataGrid[this.costomerDataGrid.CurrentRowIndex, 6].ToString();
            this.costomer_RecordTableAdapter.Fill(this.realEstatePDADataSet.Costomer_Record);
            MessageBox.Show("过滤前的dataView集合数:"+this.dataView2.Count.ToString());
            this.dataView2.RowFilter = "客户编号 = '" +deleteID+ "'";
            //this.dataView1.Sort = "来访时间";
            MessageBox.Show("过滤条件:" + deleteID);
            MessageBox.Show("过滤后的dataView集合数:"+this.dataView2.Count.ToString());
            this.costomer_RecordBindingSource.EndEdit();
            while(this.dataView2.Count!=0)
            {
                MessageBox.Show("删除第" + Convert.ToSingle(this.dataView2.Count)+ "条记录");
                this.costomer_RecordBindingSource.RemoveAt(this.dataView2.Count-1);
            }
            this.costomer_RecordTableAdapter.Update(this.realEstatePDADataSet.Costomer_Record);
                MessageBox.Show("删除成功!");

posted on 2007-02-01 20:12 放水老倌 阅读(935) 评论(0)  编辑  收藏 所属分类: .NET

只有注册用户登录后才能发表评论。


网站导航: