Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can I use an XML file to back up data from a table?

65 views
Skip to first unread message

Scott Woods

unread,
Mar 16, 2001, 5:09:49 PM3/16/01
to
In CPP builder I do the following with an ADOQuery component, I have not
tried with the command component.

qryGeneric->LoadFromFile(FileName);
qryGeneric->UpdateBatch(arAll);

Help says to make sure that ltBatchOptimistic is the lock type.

This works for SQL server.


Scott Woods

unread,
Mar 16, 2001, 5:12:32 PM3/16/01
to
One last note.

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...

Luis E. Canga

unread,
Mar 19, 2001, 4:02:13 PM3/19/01
to
really you MUST NOT provide another sql statemente nor open the dataset, to
aplly updates, you only loadfromfile and then call updatebatch(arall), is up
to the dataset to get the connection and make his work...
If you open the dataset before loading your file, and make another sql, you
are messing the full thinks.


Regards

Eduardo

Scott Woods <GCSof...@msn.com> escribió en el mensaje de noticias
3ab28fa1$1_1@dnews...

Jim Bedigan

unread,
Mar 19, 2001, 4:32:52 AM3/19/01
to
Thanks for the reply Scott.

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
>
>
>
>


Scott Woods

unread,
Mar 20, 2001, 11:29:24 AM3/20/01
to
Jim, I have not tried the command component but I can get the query
component to work with Access 2000. There should really be no difference.
Below you will find come CPP builder code that does the saveing. Basically
I have a form with three buttons and a data aware grid. There are two
queries. Query1 represents a client side ADO query with no connection and
no SQL statement. Query2 represents a server side query with a connection
to the database on the server. For my demo I pull records from an Access
2000 database with a table called customers. It has the following fields
CustID (autoincr), LastName and FirstName. The SQL for query 2 is SELECT *
FORM CUSTOMERS.

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);
}


Harry Van Tassell

unread,
Mar 21, 2001, 9:35:38 AM3/21/01
to
This may be a repeated message, I composed and sent it yesterday but with
all the problems that Borland News is having for some reason it hasn't
appeared in my news reader so I'm trying it again...
------
Jim,

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.

Scott Woods

unread,
Mar 19, 2001, 7:33:49 PM3/19/01
to
"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.

Jim Bedigan

unread,
Mar 20, 2001, 8:39:27 AM3/20/01
to
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...

Harry Van Tassell

unread,
Mar 20, 2001, 12:10:04 PM3/20/01
to
Jim,

--Hairy

0 new messages