i'm working on a project for pocket pc, which is an app that registers customers, suppliers, stocks and orders. all this is stored in the ppc itself using the SQL CE server.
i'm programming with VS2005, which is great, the tableadapters make the work lot easier.
i'm just having some problems importing and exporting data from the sql tables to files.
the export function works quiet well, i just load the data from the tableadapter into a table and then use the WriteXml(file) function.
Now, for importing I do more or less the same thing:
DataSetrTableAdapters.Customers cta = new ... etc etc
DataSetr.CustomersDataTable cdt = new DataSetr.CustomersDataTable();
cdt.ReadXml("\\My Documents\\customers.xml");
cta.Update(cdt);
result: empty table! :(
i also tried adding cta.Fill(cdt) before the update, but the result is the same....
any suggestions?
thank you very much
Hi,
The problem is that WriteXml writes the entire state of the dataset, including row state (added, modified, unchanged, etc.). When you call Fill, you add all rows to the DataSet from the table and Fill will automatically call AcceptChanges to mark all the rows as unmodified. So when you read it back from the file and call Update nothing happens - that's because the data-adapter doesn't see any row that needs processing.
I'm not sure what you're trying to achieve when reading from a file. Do you expect that those rows are *added* to the database, or you expect something more like a "merge" operation between the contents of the file and the contents of the database?
If you want to add the rows, then you have to options:
1) Avoid calling AcceptChanges on Fill. There is a property in the adapter called AcceptChangesDuringFill that you can use for that.
2) Alternatively, after loading the file into a DataSet, you can iterate over the rows and call SetAdded() on each row.
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corporation
|||i've been searching for this problem , but every page i read its about datasets.
i'n not using datasets, but datatables. the readxml is in the datatable class, not dataset. did you notice?
i want to import data to the sql server, and wipe out everything that is there. so i'll probably clean all the tables first, if necessary. after that i read from the xml and save everything again to the tables.
|||
Hi,
Actually, everything I mentioned applies to DataTable as well, including both approaches to ensure that the rows are marked as added.
If your goals is to wipe the table in the database and import the contents of the file, then you can simply first clean up the table and then use any of the options I mentioned in the previous post.
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corporation
I have the same problem.
I have a dataset, I want to fill one table in the dataset using the xml data and other table is filled by the adapter from DB. Actually the DataTable.ReadXml(filename) is not working. Am I missing anything in the XML data file. Pablo, Can you give me an example. Thanks.
Steven
No comments:
Post a Comment