Delphi Open save to XML using Microsoft.Jet.OLEDB.4.0 (.mdb)
I have a application with working in acces开发者_StackOverflows (.mdb) my connection is made using Microsoft.Jet.OLEDB.4.0 and i nead to export a MasterTable and detailtables (1,2,3) to XML is it possible? If it´s possible can i somewhere else (send by email) Open and update or insert into the database? the tables are the same only we are somewhere where it´s not possible to conect into the network where the database is.
Thank´s
When you use ADODataSet1.LoadFromFile('c:\test.xml')
you are actually creating a disconnected DataSet
.
Your option is to create a temp TADODataSet
(MyXMLDataSet
).
MyXMLDataSet
does not need the Connection
object (or a Connection string).
Use MyXMLDataSet.LoadFromFile('c:\test.xml')
and then iterate through it row by row, and post new rows to ADOTable1
or edit existing rows.
Here is an example:
MyXMLDataSet := TADODataSet.Create(nil);
try
MyXMLDataSet.LoadFromFile('c:\test.xml');
ADOTable1.Connection.BeginTrans;
try
while not MyXMLDataSet.Eof do
begin
if not ADOTable1.Locate('ID', MyXMLDataSet.FieldByName('ID').AsString, []) then
begin
// add new record
ADOTable1.Append;
ADOTable1.FieldByName('ID').AsString := MyXMLDataSet.FieldByName('ID').AsString;
// other fields...
ADOTable1.Post;
end
else
begin
// edit record
end;
MyXMLDataSet.Next;
end; // while
ADOTable1.Connection.CommitTrans;
except
ADOTable1.Connection.RollbackTrans;
raise;
end;
finally
MyXMLDataSet.Free;
end;
Note: the code above is not optimized/tested.
You can try to copy your data from your Access Datasets into some ClientDataSets and have them saved as XML.
You can then distribute the XML files to used with the ClientDataSets of your application where there is no connection available. (BriefCase model).
I would strongly recommend reading about ClentDataSets (Cary Jensen's articles for example).
You may use SimpleStorage and roll your own ADOTable data adapter.
The unit Cromis.SSA.DataSet can serve as a good starting point for that purpose.
You can use your ADOTable
to export or import tables in XML format.
codes:
for export :
ADOTable1.SaveToFile('c:\test.xml',pfXML);
for import :
ADOTable1.LoadFromFile('c:\test.xml');
精彩评论