|
代码如下: private void cmdDelete_Click(object sender, System.EventArgs e) { CheckBox cb; Equipment.EqpService.EquipmentDS.EquipmentRow removeRow; Equipment.EqpService.EqpService ws=new EqpService.EqpService(); ws.Credentials=System.Net.CredentialCache.DefaultCredentials; equipmentDS1.Merge(ws.GetEquipmentDS( ctlDept.strTempSql)); for(int i=0;i<DG.Items.Count;i++) { cb=(CheckBox)DG.Items[i].FindControl("chb2"); if (cb!=null) { if (cb.Checked==true ) { removeRow=equipmentDS1.Equipment.FindByEquipmentID(System.Decimal.Parse ( DG.DataKeys[i].ToString() )); //这里的removeRow有返回值 equipmentDS1.Equipment.RemoveEquipmentRow (removeRow); //equipmentDS1.Equipment.RemoveEquipmentRow (equipmentDS1.Equipment[DG.Items[i].DataSetIndex]); } } } if(equipmentDS1.HasChanges(DataRowState.Deleted )) { Equipment.EqpService.EqpService wts=new EqpService.EqpService(); wts.Credentials=System.Net.CredentialCache.DefaultCredentials; Equipment.EqpService.EquipmentDS xdataset; xdataset = (Equipment.EqpService.EquipmentDS)equipmentDS1.GetChanges(); wts.UpEquipmentDS(xdataset); equipmentDS1.AcceptChanges(); //msgbox BindData(); } } |
|
|
|
说明
equipmentDS1是dataset equipmentDS1.Equipment是dataset的一个表 Equipment.EqpService.EqpService 是一个webservice Equipment.EqpService.EqpService.update是weservice的一个方法,用来更新数据。 大家帮忙啊,在线等。分不够再加。 |
|
|
郁闷啊,没人吗?再加100分!!
|
|
|
你把你的代碼寫簡潔一點吧
//equipmentDS1.Equipment.RemoveEquipmentRow (equipmentDS1.Equipment[DG.Items[i].DataSetIndex]); } } } if(equipmentDS1.HasChanges(DataRowState.Deleted )) { |
|
|
我把equipmentDS1.Equipment.RemoveEquipmentRow (removeRow);
改成removeRow.Delete(); 问题已解决,问题是为何RemoveEquipmentRow 不起作用?! public void RemoveEquipmentRow(EquipmentRow row) { this.Rows.Remove(row); } 这里的this是数据行集 public EquipmentRow this[int index] { get { return ((EquipmentRow)(this.Rows[index])); } } |
|
|
DataRowCollection.Remove 方法移除行时,该行中的所有数据都将丢失。还可以调用 DataRow 类的 Delete 方法来标记某行以供移除。调用 Remove 等同于先调用 Delete 再调用 AcceptChanges。 在使用 Delete 方法后,RowState 变成 Deleted。 可通过调用 RejectChanges 取消删除行。 |
|
|
acewang(**^o^**)
你好,我想问一下,我调用Remove方法后,再查对应的行集的Count 是少了一条,不是所有数据全丢失,但是对应的HasChange却是false。你能再讲得明白点吗? 我用Delete方法成功了,可是对应的Remove方法却不行。 |
|
|
Remove方法主要是用于内存中的Dataset删除行,在界面也会显示行删除,但是在源数据库的数据还是没有变,使用它之后,rowstate是Detached,相当于状态已经定型
而delete使用后,rowstate变为deleted,这样在数据源里更新后就能回写到数据源 btw:AcceptChangs主要是在内存中的Dataset接受变化,与数据源关系不大 |
|