URGENT!!! Export to CSV file using Delphi 7

Hi experts!

I need to export my oracle data to a csv file. How do I do that? I can import the data but I don't know how to export it. I know it should be the opposite way to do it but how?

 if OpenDialog.Execute then
    begin
      //read the CSV file into a text string
      if FileExists(OpenDialog.FileName) then
      begin

        AssignFile(CSVFile, OpenDialog.FileName);
        Reset(CSVFile);

        CSVClassFileOutLine := TStringList.Create;
        //read line by line while not end of file
        CSVFileOutLine.Delimiter := ',';
        CSVFileOutLine.QuoteChar := '"';

        while not EOF(CSVFile) do
        begin
          Readln(CSVFile, CSVFileLine);
          CSVFileOutLine.DelimitedText := CSVFileLine;

        end;//end while
      end; //file exists

      CSVFileOutLine.Free;
      CloseFile(CSVFile);
    end;
end;
rodneylimAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SaLzCommented:
have a try of this.

procedure TForm1.Button1Click(Sender: TObject);
var F:TextFile;
    i : integer;
begin
 AssignFile(F, 'c:\griddata.csv');
 Rewrite(F);
 for i := 0 to stringgrid1.RowCount-1 do
 begin
  writeln(F,stringgrid1.Rows[i].CommaText);
 end;
 CloseFile(F);
end;


this is from http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_10300557.html

Sal.
0
Wim ten BrinkSelf-employed developerCommented:
You need to export your Oracle data and you're showing us how you import the CSV file. But in the while-loop you continuously replace the contents of CSVFileOutLine. By assigning a value to DelimitedText, you just repeatedly change the contents. I fear you're confusing things a little here...
0
SaLzCommented:
he said he already imported the data from the oracle to his program, he wants 2 export it, if am wrong then am sorry, bgz on me. I do apologize.

Sal.
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

SaLzCommented:
ye, hes showing us his way of importing of his csv, and he wants 2 export data from his oracle database, I was wondering the same thing, it was little confusing, but his question title was sound, export 2 csv in delphi 7.

u probly will have 2 connect 2 ur db, then list the data into the grid, then export it that way.

Sal.
0
rodneylimAuthor Commented:
Hi guys!

What I showed was my import of my csv file to my oracle data. The loop is to write line by line into the oracle database. It is just to show what I have done on the import side. What I do not know is how to export the existing oracle database back into a csv file. It is just the opposite way of what I have done which I think I still have to use the while loop right?

Example of the CSV file when opened with a notepad.
133456, "Finance 100", "School of Business"

I hope I explained more clearly this time! Thanks guys!
0
kretzschmarCommented:
var
  s : string;
  i : integer;
begin  
  adoquery.sql.text := 'YourSelectYouHave';
  adoquery.open;
  AssignFile(CSVFile, SaveDialog.FileName);
  Rewrite(CSVFile);
  while not adoquery.eof do
  begin
    s := '';
    for i := 0 to adoquery.fields.count - 1 do
      if adoquery.fields[i].DataType = ftString then
         s := s+'"'+adoquery.fields[i].AsString+'",'
      else
         s := s+adoquery.fields[i].AsString+',';
    delete(s,length(s),1);  //delete last comma
    writeln(CSVFile,s);
    adoquery.next;
  end;
  adoquery.close;
  closefile(CSVFile);
end;

just from head

meikl ;-)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kretzschmarCommented:
hello?
0
rodneylimAuthor Commented:
sorry for the delay...it is been a hectic period for me! thanks for your help kretzschmar!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.