hi people,
I'm noob on that ops:
i have to save the result of a query in a text file, which is the easiest way for do that?
I don't want to install new components i think delphi standard is enought (i'm using delphi 5)
ty for help.
hi people,
I'm noob on that ops:
i have to save the result of a query in a text file, which is the easiest way for do that?
I don't want to install new components i think delphi standard is enought (i'm using delphi 5)
ty for help.
Will: "Before you learn how to cook a fish you must first learn how to catch a fish." coolest
Can you provide a bit more information on what exactly you are wanting to do? Saving the results of a query to a text file is a bit vague. Are you looking to do something like in SQL Server Management Console where you can copy the results and paste them into a text file, and if so what Database are you working out of? Are you using a generic provider like ADO and want a generic storage hander? Do you want cross platform or just windows? I could go on, but I think you get the idea.
- Jeremy
http://www.eonclash.com/
I connect through ODBC to a mysql server;
the server is running winxp and the client too, i'm using Tquery component for execute query.
i just wanna save the result of a select query on a file with column separetor, ex:
name|surname|age|etc..
Will: "Before you learn how to cook a fish you must first learn how to catch a fish." coolest
This code snippet assumes that the query is already open. It puts " around strings and uses a comma for the separator, and dumps each record as a new line in a TMemo component.
[pascal]
var
fieldLoop : integer;
temp : string;
begin
while (not qry.eof) do
begin
temp:='';
for fieldLoop:=0 to qry.fieldCount-1 do
begin
if (temp<>'') then
temp:=temp+',';
if (qry.Fields[fieldLoop] is TStringField) then
temp:=temp+'"'+qry.fields[fieldLoop].asString+'"'
else
temp:=temp+qry.fields[fieldLoop].asString;
end;
memo1.lines.add(temp);
qry.next;
end;
end;
[/pascal]
Its probably not perfect in that there are possibly other field types that should be wrapper in quotes, but its a start.
:: AthenaOfDelphi :: My Blog :: My Software ::
ty i made something like this and work good:
Code:procedure TForm1.SaveReport(const id_report: string); var sSql,s, sCampi: String; F1: Textfile; begin try // - STEP 010 sSql :='SELECT ......something '; setQry(sSql,qry_dyn); qry_dyn.Active := True; qry_dyn.First; Savedialog1.DefaultExt:='*.csv'; SaveDialog1.Filter := 'Comma separeted files (*.csv)|*.CSV|Text files (*.txt)|*.TXT'; if SaveDialog1.Execute then AssignFile(F1, SaveDialog1.Filename) else Exit; Rewrite(F1); while not qry_dyn.Eof do begin writeln(F1, qry_dyn.FieldByName('a').AsString + '|' + qry_dyn.FieldByName('b').AsString + '|' + //..... qry_dyn.FieldByName('z').AsString); qry_dyn.Next; end; //while if (Debug_enable > 1) then caricaLogProcedure('TForm1.SaveReport;','010','OK',''); except try Closefile(F1); except //errore nella chiususa file ShowMessage('Errore duranta la scrittura del tipo1, impossibile chiudere il file'); end; ShowMessage('Bugggone!'); if (Debug_enable > 0) then caricaLogProcedure('TForm1.SaveReport;','010','KO',sSql); end; Closefile(F1); end;
Will: "Before you learn how to cook a fish you must first learn how to catch a fish." coolest
Bookmarks