Hi, Leonard!
Well, it takes as long as it takes to get data from or put data to
Access. It is certainly easier to copy from your application database to
an external database using the C++Builder database components...
Here's a sample form with database components (you can copy this text
and paste it onto a form - the controls will appear)...
object Button1: TButton
Left = 40
Top = 32
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 0
OnClick = Button1Click
end
object FromTable: TADOQuery
ConnectionString =
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\db1' +
'.mdb;Persist Security Info=False'
Parameters = <>
SQL.Strings = (
'SELECT * FROM Table1')
Left = 48
Top = 96
end
object ToTable: TADOQuery
ConnectionString =
'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\db2' +
'.mdb;Mode=ReadWrite;Persist Security Info=False'
Parameters = <>
Left = 48
Top = 136
end
Here's the event handler to copy the data...
void __fastcall TForm1::Button1Click(TObject *Sender)
{
FromTable->First();
while (!FromTable->Eof)
{
ToTable->Append();
for
(
int FromTableFieldIndex = 0;
FromTableFieldIndex < FromTable->FieldCount;
FromTableFieldIndex++
)
{
ToTable->FieldByName
(
FromTable->Fields->Fields[FromTableFieldIndex]->FieldName
)->Value =
FromTable->Fields->Fields[FromTableFieldIndex]->Value;
};
ToTable->Post();
FromTable->Next();
};
Just change the database connection string using the "ConnectionString"
property of the TADOQuery objects to be the appropriate from and to
databases... and everything should work. Now, if the source and
destination databases have different field names, you can simply setup a
lookup table (perhaps with the TStringList class using name=value pairs)
that matches the source table field name to the destination field name.
You can even make a rule that if a field is not found in that table, you
don't copy the data. And, of course, there's more possibilities, if you
need them. But see if this helps.
I hope it does...
------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------