Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > DB-Aware

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 11-26-2015, 03:31 PM
musdim musdim is offline
Junior Member
 
Join Date: Nov 2015
Posts: 1
Default How do export each record dbgrid in a separate text file

Hello dear friends I'm learning new Delphi
My table as follows
-fields1 caption is char
-fields2 contents is memo

so
filename.txt will fields1
content will be fields2

There are a total of 3000 record.
I want to save each of the DBGrid who appear on them in a separate text document.
as a result, 3000 will be a text document.
I'm very glad if you can help Thank you in advance.
Reply With Quote
  #2  
Old 11-26-2015, 04:09 PM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 7,323
Default

No Delphi running, but it should be something like this (replace the adoquery with a dataset, I don't do UI development), assuming your grid is a DBGrid

Code:
procedure TForm1.Button1Click(Sender: TObject);
var 
  query: TADOQuery;
  content: TStrings;
begin
  query := 'SELECT * FROM [yourtable];
  query.Open();
  while not query.Eof do
  begin
    content := TStringList.Create();
    try
      content.Text := query.FieldByName('text').AsString;
      content.SaveToFile('.\'  + query.FieldByName('filename').AsString);
    finally
      content.Free();
    end;
    query.Next();
  end;
end;
Ofcourse this should be optimized, error handling and so on, but this is to get the general idea...
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 06:42 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.