Unit AccessImport;
// example script for import data from access database
// this script use WelfareUC2 database as sample file
// version 0.1
// 2005-07-11
// Chaiyaporn Suratemekul
procedure Main;
var
sconnection:string; // variable for hold connection string
st:string; // variable for hold any string
begin
sconnection:='Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;'+
'[color=red]Data Source=D:\TEST.mdb[/color];'+ // change access filename here
'Mode=Share Deny None;Extended Properties="";Jet OLEDB:System database="";'+
'Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=5;'+
'Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;'+
'Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";'+
'Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;'+
'Jet OLEDB:Don''t Copy Locale on Compact=False;'+
'Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False ';
// jconnection is remote database connection
// you can set jconnection to connected any database
jconnection.connected:=false;
jconnection.protocol:='ado';
jconnection.database:=sconnection;
jconnection.connected:=true;
// jquery is remote dataset object
// use jquery to get remote data
jquery.close;
// set sql statement
// select sample data from table ucdata just 10 records
jquery.sql.text:='[color=red]select top 10 * from EXPORT[/color]';
// open dataset
jquery.open;
// zquery is dataset point to current database (hosxp database)
// this example try to erase old data from table tempreport
// table tempreport use to t store temporary report data
// but can use to hold any temp data too
zquery.close;
// delete all data from tempreport
zquery.sql.text:='delete from tempreport';
zquery.execsql;
zquery.close;
// open table tempreport
zquery.sql.text:='select * from tempreport';
zquery.open;
// loop dataset until end of file (first to last record)
// when open dataset record pointer is at first record by default
while not jquery.eof do
begin
// prepare to insert data to temptable
zquery.insert;
zquery.fieldbyname('id').asstring:=jquery.fieldbyname('pid').asstring;
// insert data from access field fname + lname to table tempreport field name
zquery.fieldbyname('name').asstring:=
jquery.fieldbyname('fname').asstring+' '+jquery.fieldbyname('lname').asstring;
zquery.fieldbyname('name1').asstring:=jquery.fieldbyname('sex').asstring;
// now commit change to database
zquery.post;
jquery.next;
end;
jquery.close;
zquery.close;
showmessage('Import OK');
// ok now open table tempreport to see what happen
end;
end.