开发者

Using TADOQuery result in another query?

Using Delphi 2009. I have a TADOConnection to folder containing a csv file and a TADOQuery that pulls data from a csv file in there (Call it TADOQueryCSV). That works OK.

I also have a second TADOConnection to an Access database with a table called AccessTbl_TEMP and various TADOQueries that process data in there. They work OK.

Now I want to process开发者_运维技巧 the data returned by the TADOQueryCSV and insert it into the table in the Access database. But how do I refer to the data returned from the csv file.?

I need something like this but don't know how to write the FROM clause.

INSERT INTO AccessTbl_TEMP ( Field1,Field2 ) SELECT csvField1, csvField2 FROM TADOQueryCSV;


You can move the data in code in Delphi. dsSource is TADOQueryCSV and dsTarget is the table AccessTbl_TEMP.

dsSource.First;
while not dsSource.Eof do
begin
    dsTarget.Append;
    // Assign field values from dsSource to dsTarget
    dsTarget.Post;
    dsSource.Next;
end;


You have to use the MS Access linked tables, where a linked table will point to a CSV file.


Try this is faster way :

for x := 0 to Source.fieldcount - 1 do
begin
Target.fieldbyname(Source.fields[x].fieldname).value :=
Source.fields[x].value;
except
end;
end;

using value will convert the data for you. using the try / except concept will keep you from having to determine if the field is there

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜