qryGeneric->LoadFromFile(FileName);
qryGeneric->UpdateBatch(arAll);
Help says to make sure that ltBatchOptimistic is the lock type.
This works for SQL server.
You do not need to provide the SQL statement or even open the query /
recordset. LoadFile opens the recordset with the correct data. The table
information is encapsulated within the XML file.
Good luck.
"Scott Woods" <GCSof...@msn.com> wrote in message
news:3ab28efe$1_1@dnews...
Regards
Eduardo
Scott Woods <GCSof...@msn.com> escribió en el mensaje de noticias
3ab28fa1$1_1@dnews...
I have tried the following code but the data is still not imported into my
table.
What am I doing wrong?
with ADODataSet1 do begin
Connection := ADOConnection1;
CursorLocation := clUseServer;
CursorType := ctKeyset;
LockType := ltBatchOptimistic;
CommandType := cmdText;
CommandText := 'SELECT * FROM INSTIT';
Open;
LoadFromFile('test.xml');
UpdateBatch(arAll);
Close;
end;
In this example, my table is called 'INSTIT' and the file containing the
data (TEST.XML) was created earlier using SaveToFile from a populated copy
of INSTIT.
One important bit of information I omitted earlier is that I am using
Access2000, rather than SQL Server as the database back-end. Maybe it
doesn't work in Access?
Jim Bedigan <jim.b...@btinternet.com> wrote in message
news:3ab1f2f7_1@dnews...
> Hi
>
> Id like to use an XML file to back up data from a table.
>
> I've managed to save the data using TCustomADODataSet.SaveToFile but
cannot
> find a way to retrieve the data at a later time. I have tried to use
> CustomADODataSet.LoadFromFile, which APPEARS to import the data but I find
> that this is not 'locked' into the target table when the dataset is
closed.
>
> Further investigation using a TADOTable component to handle the dataset
> shows that immediately after the LoadFromFile operation completes, the
> TableName property no longer holds its original value (the table name) but
> now contains the XML file name instead. This implies that the table
> cursor is now pointing at the XML file rather than the destination table
> (??)
>
> Am I missing something here? All I want to do is to import data stored
in
> XML format into an existing table.
>
> If it IS possible to do this, I'd also be interested to know if its
possible
> to dynamically create a new table based on the contents of an XML file
> (exported from a table on another machine).
>
> Any suggestions?
>
> Thanks
>
>
>
>
void __fastcall TForm1::btnFetchClick(TObject *Sender)
{
// Pull data from the server into an XML file and save to disk.
ADOQuery2->Active = true;
ADOQuery2->SaveToFile("Junk.xml",pfXML);
ADOQuery2->Active = false;
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::btnSetClick(TObject *Sender)
{
// Load data from the file on the client side. This will populate the DB
Grid which has a datasource with its
// dataset set to ADOQuery1.
ADOQuery1->LoadFromFile("Junk.xmL");
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::btnSaveClick(TObject *Sender)
{
// After editing the Grid (adding customers - NOTE: Do not edit the
AutoInc field) clicking the save button
// writes the client side data to an XML file for the server side
component to reopen and apply the changes to the
// database on the server machine.
ADOQuery1->SaveToFile("Junk.xml",pfXML);
ADOQuery1->Close();
ADOQuery2->LoadFromFile("Junk.xml");
ADOQuery2->UpdateBatch(arAll);
}
I have no earthly idea why you want to use XML to backup Access tables, but
you surely ain't gonna get there from where you are coming from. I assume
you want to save the table to disk in XML recordset format then restore it
in it's entirety to an empty table in the same or some other Access
database.
What you are actually doing is persisting the ADO RecordSet to disk and then
restoring it back to a new recordset. If the original RecordSet was
ClientSide, Static, Modifiable, and BatchOptimistic you can save/restore it
in an updateable format but carefully notice the term - UpDateable...
In the XML file will be a lot of recordset information, the complete schema,
most of the dynamic properties, and all the row data including original
field values plus any changed field values and any newly added rows and each
row will have tags that translate into a status value showing if it is
modified, new, deleted, etc.
When you do a batch update it is the recordset status value which determines
what gets updated in the database. If a row hasn't somehow been touched
since it was saved it will not be updated - OK see your problem? You would
need have all the rows with a status value of "new" and in your case they
all have the value of "unmodified". In ADO the recordset status is readonly
and I don't know any tricks to flip it to "new".
If by now you haven't lost all interest in this take a careful look at the
example in ...\Demo\ADO\BriefCase. The code is a bit obfuscated but you can
figure it out. Change the filename extension to 'Employee.XML' and the
SaveToFile parameter to pfXML and it will generate a XML file which you can
then display in a text editor or Internet Explorer or better yet a XML
editor like XMLSpy. Save it then reload and change it then resave it and
inspect the changes.
--Hairy
"Jim Bedigan" <jim.b...@btinternet.com> wrote in message
news:3ab75d49_2@dnews...
> Ok - my code now looks like this:-
>
> with ADODataSet1 do begin
> Connection := ADOConnection1;
> CursorLocation := clUseServer;
> CursorType := ctKeyset;
> LockType := ltBatchOptimistic;
> CommandType := cmdText;
> LoadFromFile('test.xml');
> UpdateBatch(arAll);
> end;
>
> but still no joy with Access2000.
>
> Has anyone succeeded with Access?
>
>
> Scott Woods <GCSof...@msn.com> wrote in message news:3ab6a541_1@dnews...
> > "Luis E. Canga" <lca...@satlink.com> wrote in message
> > news:3ab67486_2@dnews...
> > > really you MUST NOT provide another sql statemente nor open the
dataset,
> > to
> >
> > Thats what I said.
Thats what I said.
with ADODataSet1 do begin
Connection := ADOConnection1;
CursorLocation := clUseServer;
CursorType := ctKeyset;
LockType := ltBatchOptimistic;
CommandType := cmdText;
LoadFromFile('test.xml');
UpdateBatch(arAll);
end;
but still no joy with Access2000.
Has anyone succeeded with Access?
Scott Woods <GCSof...@msn.com> wrote in message news:3ab6a541_1@dnews...
--Hairy