DataSet.WriteXml problems after rows deleted. Bug?

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

I'm writing xml files from a typed dataset, but having problems after a row
has been deleted. Adding a row to an empty dataset and writing the xml i get
(for example)

<ScreenConfigDataset xmlns="http://tempuri.org/ScreenConfigDataset.xsd">
<DialectScreenConfig>
<FlavourID>1</FlavourID>
<FormID>EmployeeMaintenance</FormID>
<ControlKey>EmployeeNo</ControlKey>
<ItemKey>EmployeeNo</ItemKey>
<BackgroundColour>Yellow</BackgroundColour>
</DialectScreenConfig>
</ScreenConfigDataset>

which is fine, but then if I go and mark the row for deletion and write xml
again I get the invalid xml :-

<ScreenConfigDataset xmlns="http://tempuri.org/ScreenConfigDataset.xsd" />
<DialectScreenConfig>
<FlavourID>1</FlavourID>
<FormID>EmployeeMaintenance</FormID>
<ControlKey>EmployeeNo</ControlKey>
<ItemKey>EmployeeNo</ItemKey>
<BackgroundColour>Yellow</BackgroundColour>
</DialectScreenConfig>
</ScreenConfigDataset>

I would have expected the deleted row not to be written to xml. Am I doing
something wrong or is this a bug ?
 
Hi JezB,

Deleted rows are persisted becuase adapter should know which row to delete.
If a row is added and then deleted it won't be persisted (since there is no
row in database to delete).
Or, you might consider Remove-ing rows.
 
Hi JezB,

Something adding to Miha, although just a little bit.

In a dataset you can mark a row as deleted or you can remove it.
This is important if you use a dataadapter, because that is used to update
the database.

If you not are using a dataadapter.update you can use remove (or removeat).
What also is posible, is to do mydataset.acceptchanges after the delete.

(But do not do that when you are using the dataadapter.update with a full
dataset and certainly not for the update).

The dataadapter.update does (if you give him the full dataset) the
acceptchanges for you.

I hope this helps a little bit more?

Cor
 
Yes I do want deleted rows to be persisted to the DATABASE, and i pass the
full dataset to the data services layer to handle all this. All I'm trying
to do is write the current state of the database rows to a local xml "cache"
file, excluding rows that have been deleted.

Funny thing is this DOES do exactly as I want it to when writing xml to the
a specific directory, but I was trying to improve this by writing to the
isolated storage area, and that's what introduced the problem.

I think it's a bug.
 
More Info: The problem only occurs when I write to the isolated storage
area. For example :-

// Write to isolated storage
string xmlFile = "test.xml";
IsolatedStorageFileStream ifs = new
IsolatedStorageFileStream(xmlFile,FileMode.OpenOrCreate, FileAccess.Write,
isoStore);
StreamWriter sw = new StreamWriter(ifs);
myDataSet.WriteXml(sw);
sw.Flush();
sw.Close();

// write to exe directory
string xmlFile2 =
string.Format("{0}test.xml",AppDomain.CurrentDomain.BaseDirectory);
StreamWriter sw2 = new StreamWriter(xmlFile2);
myDataSet.WriteXml(sw2);
sw2.Flush();
sw2.Close();

The file in isolated storage has the problem (it writes the deleted row to
xml but in an invalid format), but the xml file in my base directory doesn't
(it simply excludes the deleted row, which is what i want).

I THINK THIS IS A BUG !
 
Sorry I forgot to include the declaration:
IsolatedStorageFile isoStore =
IsolatedStorageFile.GetStore(IsolatedStorageScope.User |
IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);

in my example code. So if you spotted this then this is not what's causing
the problem!
 
Yes thanks - it doesnt really help. The dataset persists to the database
without any problem, including deleting rows. This is a separate issue
writing the current contents of the dataset to a local xml file - I dont
want to Remove the rows since this is the same dataset as I send to the data
services layer for saving changes to the database, and this needs deleted
rows to be simply marked for delete.
 
Hi JezB,

I do not full understand your question but if I understand it partaly right
I would try

dim datasetNew as new dataset or
Dataset datasetNew = new Dataset();

datasetNew = mydataset.copy
and then
datasetNew.acceptchanges
datasetNew.writeXML(......................

(; at the end with C#)

And give that a try?.

Cor
 
Back
Top