![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
|
Hi, It depends on what kind of delete you do. If you call someRow.Delete(), the RowState of this row is set RowState.Deleted, and the DataAdapter will call the Delete statement. If the return is 0 (nothing has been deleted) exception is thrown. So, If you want to cancel the addition of the row, you have to call DataTable.Rows.Remove(DataRow). To check which rows are added, you can iterate through the rows with the RowState.Added using: DataTable.DefaultView.RowStateFilter = DataViewRowState.Added; while(DataTable.DefaultView.Count > 0) DataTable.Rows.Remove(DataTable.DefaultView[0].Row); Eli. -----Original Message----- I'm using dataGrid connected to the dataSet and dataSet connected to the table through dataAdapter. dAdap = new SqlCeDataAdapter( "SELECT field1, field2, field3 FROM Table", conn ); SqlCeCommandBuilder cb = new SqlCeCommandBuilder(dAdap); dAdap.Fill( dSet, "Table"); dataGrid1.DataSource = dSet.Tables["Table"]; It works fine except one thing: Let's say I have 3 records in the table and I insert two more with the commands: dSet.Tables["Table"].Rows.Add(new Object[] {null, "Value1", "Value2"}); dAdap.Update(dSet,"Table"); If I want to delete the last two records the following error message appear: "Concurrency violation: the DeleteCommand affected 0 records." There is no problem with deleting the first three records. I'm using the following code to delete particular record: dr = dSet.Tables["Table"].Rows[dataGrid1.CurrentRowIndex]; dr.Delete(); dAdap.Update(dSet,"Table"); Thank you Gec . |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |