I need to save my deleted records in my disconnected app.
This doesent work.
DataTable deletedrecords = ds.Tables[0].GetChanges(DataRowState.Deleted);
if(deletedrecords != null)
{
DataSet ds = new DataSet();
ds.Merge(deletedrecords);
ds.WriteXml("DeletedRecords.XML");
}
Any ideas
Thanks in advance.
Greg.

How to save Deleted records in DataSet?
WhatIsBigBang
You must do the above routine after the changes are made but <I>before</I> the AcceptChanges method is called.
How are you allowing the rows to be deleted
amaly0827
If you need your application to keep track of changes, then you must monitor the changes made by the user, call GetChanges to save a copy of the differences, and then call AcceptChanges to apply them to the DataSet. You can then later update the DataBase from the DataSet.
Here is a code snippet from MSDN on making and monitoring changes in a datagrid:
Private Sub EditGrid(myGrid As DataGrid)
' Get the selected row and column through the CurrentCell.
Dim colNum As Integer
Dim rowNum As Integer
colNum = dataGrid1.CurrentCell.ColumnNumber
rowNum = dataGrid1.CurrentCell.RowNumber
' Get the selected DataGridColumnStyle.
Dim dgCol As DataGridColumnStyle
dgCol = dataGrid1.TableStyles(0).GridColumnStyles(colNum)
' Invoke the BeginEdit method to see if editing can begin.
If dataGrid1.BeginEdit(dgCol, rowNum) Then
' Edit row value. Get the DataTable and selected row.
Dim myTable As DataTable
Dim myRow As DataRow
' Assuming the DataGrid is bound to a DataTable.
myTable = CType(dataGrid1.DataSource, DataTable)
myRow = myTable.Rows(rowNum)
' Invoke the Row object's BeginEdit method.
myRow.BeginEdit()
myRow(colNum) = "New Value"
'Here is where you would insert the code to get a copy of the changes prior to calling AcceptChanges.
' You must accept changes on both DataRow and DataTable.
myRow.AcceptChanges()
myTable.AcceptChanges()
dataGrid1.EndEdit(dgCol, rowNum, False)
Else
Console.WriteLine("BeginEdit failed")
End If
End Sub 'EditGrid
Now, this example is for changing values programatically. Since you are trying to capture changes made by the user, you will have to call a modified version of this routine in the DataGrid.CurrentCellChanged event. Something like:
'Handle the DataGrid.CurrentCellChanged event
Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
'See if the DataSet has changes
If myDataSet.HasChanges Then
'Use the GetChanges method to get a new DataSet with the changes
'Append this new dataset to the global "DataChanges" dataset you created, or append your XML file directly
'Call the AcceptChanges method
End If
End Sub
You <B>must</B> implement the HasChanges, GetChanges, and AcceptChanges methods in your code somewhere in order to properly capture and record changes to the DataSet.
Gu&#38;&#35;240&#59;mundur
I think I got the hang of it works now.
One of the major cause was the acceptchanges thing that I didn't do at the right time.
Thanks again.
/Greg
Skafever
My app is mentioned to be used in an disconnected mode.
The User first get the data from the databas online that the user want to edit offline.
Back in office the user should be able to save the manipulated data back to the databas.
I have moved further one with my problems to try to understand how it really works.
I have managed to save the data back to the databas with both new/modifed and deleted records.
The problem is that when i read the saved xml it seems that the XmlReadMode.DiffGram doesen't work for deleted records
The dataset is used in a Datagrid and the delete i just done with the Delete from the keyboard.
The if statement: if(deletedrecords != null), is one and the dataset with "deleted" records are written to the disc, but it's empty.
In the debug mode I can se that the records are in "DeletedRowInaccessibleException" is this the problem
When I have done a change in the datagrid and want to save it for later use, I save the Dataset with: ds.writexml(filename, XmlWriteMode.Diffgram)
The changes is saved in the file but the deleted stuff seems to be saved in some other form.
Later the client can read it back with ds.readxml(filename, XmlReadMode.Diffgram)
For the datagrid i just use the
dataviewmanager.DataViewSettings[0].RowStateFilter = DataViewRowState.CurrentRows;
What is the best approch for building an offline/disconnected app
Use xml Use msde Use what
Thanks again.
/Greg