[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1653
  • Last Modified:

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;
0
rodneylim
Asked:
rodneylim
  • 3
  • 2
  • 2
  • +1
1 Solution
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
kretzschmarCommented:
hello?
0
 
rodneylimAuthor Commented:
sorry for the delay...it is been a hectic period for me! thanks for your help kretzschmar!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now