d4jaj1
asked on
BatchMove - Data from Pdox to DBase/ASCII
How can I perform a Batchmove from Paradox table to a DBase or ASCII table? As you can see in the code below, I run an SQL query, create the Destination Table (DB, DBF or TXT) and try to execute the Batchmove. I get an error of Invalid Extentsion when either DBF or TXT is choosen. Is there a 'single' compoenent/piece of code that will fit into my existing code? Thanks.
try
with Query1 do begin
Active := False;
SQL.Clear;
sql.add(querystring);
Open;
end;
temptbl := TTable.Create(nil);
with temptbl do begin
Active := False;
DatabaseName := ExtractFilePath(TabNameEdi t.text);
TableName := Extractfilename(TabNameEdi t.text);
case TypeBtn.itemindex of
1: TableType := ttParadox;
2: TableType := ttDBase;
3: TableType := ttASCII;
end;
end;
try
with BatchMove1 do begin
Source := Query1;
Destination := temptbl;
Execute;
end;
finally
temptbl.Free;
end;
finally
//lst.Free;
end;
try
with Query1 do begin
Active := False;
SQL.Clear;
sql.add(querystring);
Open;
end;
temptbl := TTable.Create(nil);
with temptbl do begin
Active := False;
DatabaseName := ExtractFilePath(TabNameEdi
TableName := Extractfilename(TabNameEdi
case TypeBtn.itemindex of
1: TableType := ttParadox;
2: TableType := ttDBase;
3: TableType := ttASCII;
end;
end;
try
with BatchMove1 do begin
Source := Query1;
Destination := temptbl;
Execute;
end;
finally
temptbl.Free;
end;
finally
//lst.Free;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try this one, Don't forget to free the objects:
procedure TForm1.Button1Click(Sender : TObject);
var
t2: tTable;
t1: tQuery;
begin
t1 := TQuery.create(self);
with t1 do begin
DataBaseName := 'DBDEMOS';
SQL.Add('select * from customer where country='+chr(39)+'US'+chr (39));
open;
end;
t2 := tTable.create(self);
with t2 do begin
DataBaseName := 'c:\temp';
tableName := 'myfile.txt';
TableType := ttASCII;
CreateTable;
open;
edit;
BatchMove(t1, batCopy);
close;
end;
t1.close;
end;
procedure TForm1.Button1Click(Sender
var
t2: tTable;
t1: tQuery;
begin
t1 := TQuery.create(self);
with t1 do begin
DataBaseName := 'DBDEMOS';
SQL.Add('select * from customer where country='+chr(39)+'US'+chr
open;
end;
t2 := tTable.create(self);
with t2 do begin
DataBaseName := 'c:\temp';
tableName := 'myfile.txt';
TableType := ttASCII;
CreateTable;
open;
edit;
BatchMove(t1, batCopy);
close;
end;
t1.close;
end;
ASKER
Thanks,
I had to remove the;
CreateTable;
open;
edit;
to get it to work for both DBase & Txt files.
I had to remove the;
CreateTable;
open;
edit;
to get it to work for both DBase & Txt files.
ASKER
but can't I move datafrom the Query directly to a TXT or DBF file. When I run my code above, it works fine when moving the data to a DB file, but raises an exception when trying to move to the others. Is it necessary to batchmove the query results to a DB file FIRST, then batchmove AGAIN to a TXT or DFB file?