Solved

How to take a record set from one table and insert it into another table?

Posted on 2010-09-08
12
452 Views
Last Modified: 2012-06-21
I have a marketing application that is to do the following:

User picks from a data entry form an Issue Name (Calendar 2010 for example) and a Mailing List (Contractors for example). Calendar 2010 is IssueID 1 and the Contractors Mailing List should query the ContactsView for all records where Contact_Type = 'Contractor'. Let's say there are 200 records that are 'Contractor' records. Now what I want to do when the user picks these 2 items and clicks a button called 'Export' is that each of those records in the ContactsView that matched the Mailing List (200 records) be added to a table called 'MarketingHistory' where it saves the ContactID, address fields and email address of the contacts as well as the IssueID of 1. I just need it to save the contact records that belong in the mailing list (per a query) as well as the IssueID and put them in as new records into the MarketingHistory table.

Thanks!
0
Comment
Question by:Bianca
12 Comments
 
LVL 13

Expert Comment

by:rfwoolf
ID: 33628710
What database?
e.g. in SQL Server you there is a INSERT INTO function.
In Delphi you can replicate a dataset using a TClientDataSet.
0
 

Author Comment

by:Bianca
ID: 33631380
into SQL, how do I accomplish this with the TClientDataSet?
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 33633045

Use the ClientDataset clone cursor method

TCustomClientDataSet.CloneCursor(Source: TCustomClientDataSet; Reset, KeepSettings: Boolean);
0
 

Author Comment

by:Bianca
ID: 33636885
sorry I'm still a bit new to all this... how exactly would I do that?
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 33643576
CloneCursor will not work in your case. If you are using two client datasets you can directly assign data from one to the other ie
ClientDatset1.Data := ClientDatset2.Data
This creates an exact copy of ClientDataset2
Then call ClientDatset1.ApplyUpdates(0)

If you want more control of what you are copying, here is a sample object that will copy records from one dataset to another and save to database. You can create new objects to match the components that you are using since this is based on a TClientDataset and DBExpress TSQLQuery.
CopyDataset.zip
0
 

Author Comment

by:Bianca
ID: 33666954
So for example I run a query "SELECT * from Contacts where contact_Type = 'Contractor" and gives me 500 records... how do I literally state that the results from that select := ClientDataset1?

I guess I am not sure how to call the results, then with the results, post it to another table along with additional data such as exportdate and marketingtype.

Thanks!
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 32

Expert Comment

by:ewangoya
ID: 33668720
Here is an example using (SQL Server) Northwind database, ado datasets and TClientDataset
I set up the source dataset with TADODataset to read from Employees table. I created a new table "EmployeesCopy" which is the destination table accessed by the ClientDataset.

Just pass in your dataset and the Clientdataset, to "TClientDatasetCopy". This will extract the data from your source dataset and create records in the db.

This is not a production object but use it as a template to create your own object to copy data;

TestApp.zip
0
 

Author Comment

by:Bianca
ID: 33685010
HEre's the code I have but it only copies the FIRST record..

// insert new record in Marketing_EMarketing_History
    with gvEMarketingRecipients do begin
      //Update the datacontroller with the new date values.
      for J := 0 to gvEMarketingRecipients.DataController.FilteredRecordCount - 1 do begin
        iRecIndex   := DataController.FilteredRecordIndex[J];
        iContactID  := gvEMarketingRecipients.DataController.GetValue(iRecIndex, gvEMarketingRecipientsID.Index);
//        sEmail      := gvEMarketingRecipients.DataController.GetValue(iRecIndex, gvEMarketingRecipientsEmail.Index);
      end;

        // update Marketing_Emarketing_History table with new contact info.
        with dmMarketing.qrySearch do begin
          Close;
          sql.Clear;
          SQL.Add('SELECT * FROM Marketing_EMarketing_History WHERE ContactID = ' + IntToStr(-1) + ' AND Issue =''' + sIssue + '''');
          Open;
          Insert;
          FieldByName('ContactID').AsInteger    := iContactID;
          FieldByName('Issue').AsString         := sIssue;
          FieldByName('Address2').AsString      := gvEMarketingRecipients.DataController.GetValue(iRecIndex, gvEMarketingRecipientsEmail.Index);
          FieldByName('ExportDate').AsString    := DateToStr(Now);
          FieldByName('ExportBy').AsString      := gasBinder.UserID;
          Post;
          end;  // with qrySearch2
        frmProgress.ProgressBar.StepBy(1);
        frmProgress.Refresh;
        end;
      end;  // for J := 0 to...
   FreeAndNil(frmProgress);
end;
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 33685647
Just to make sure
you are reading the data from dmMarketing.qrySearch
and want to copy the records into qrySearch2
0
 
LVL 32

Accepted Solution

by:
ewangoya earned 500 total points
ID: 33685878
This will add all the records in the grid view to your query

with gvEMarketingRecipients do begin
    //Update the datacontroller with the new date values.
    for J := 0 to gvEMarketingRecipients.DataController.FilteredRecordCount - 1 do begin
      iRecIndex   := DataController.FilteredRecordIndex[J];
      iContactID  := gvEMarketingRecipients.DataController.GetValue(iRecIndex, gvEMarketingRecipientsID.Index);
      // sEmail      := gvEMarketingRecipients.DataController.GetValue(iRecIndex, gvEMarketingRecipientsEmail.Index);

      // update Marketing_Emarketing_History table with new contact info.
      with dmMarketing.qrySearch do
      begin
        Close;
        SQL.Clear;
        SQL.Add('INSERT INTO Marketing_EMarketing_History ') +
        SQL.Add('(ContactId, Issue, Address2, ExportDate, ExportBy)');
        SQL.Add('VALUES (:ContactId, :Issue, :Address2, :ExportDate, :ExportBy)');
        SQL.Add(Format('WHERE ContactID = %s AND Issue = %s', [IntToStr(-1), QuotedStr(sIssue)]);

        ParamByName('ContactID').AsInteger := iContactID;
        ParamByName('Issue').AsString := sIssue;
        ParamByName('Address2').AsString := DataController.GetValue(iRecIndex, Index);
        ParamByName('ExportDate').AsString := DateToStr(Now);
        ParamByName('ExportBy').AsString := gasBinder.UserID;
        ExecSQL;
      end;  // with qrySearch2
      frmProgress.ProgressBar.StepBy(1);
      frmProgress.Refresh;
    end;// for J := 0 to...
  end;
0
 
LVL 32

Expert Comment

by:ewangoya
ID: 33686681
This answer has already been provided by
jimyX
0
 
LVL 8

Expert Comment

by:GeneralTackett
ID: 33721053
This code does that and also matches fields so you can map from 1 to another even with different names  I can provide the full project if needed
Unit Main;


{-----------------------------------------------------------------------------------}
{                                                                                   }
{Program Description and Functionality list                                         }
{Functions                                                                          }
{01..Transfer data from source to Destination using batch move                      }
{02..Allow mapping of data during transfer                                          }
{03..Allow selection of alias or path source and destinations                       }
{04..convert data from txt to any supported database (minus indexing)               }
{05..Convert data from DB to TXT                                                    }
{06..Convert data to Excel                                                          }
{07..allow SQL source to be a selected subset                                       }
{08..allow data to be updated based upon comparison of a field for a matching value }
{09..                                                                               }
{-----------------------------------------------------------------------------------}

Interface

Uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls,
  sysutils, StdCtrls, DBTables, DB, Grids, Buttons, ExtCtrls, tables, DBGrids,
  Outline, DirOutln,  Menus, ComCtrls, Dialogs;
  
Type
  Tmaindlg = class(TForm)
    Source: TTable;
    destination: TTable;
    ds_source: TDataSource;
    ds_destination: TDataSource;
    sql: TQuery;
    ds_sql: TDataSource;
    MainMenu1: TMainMenu;
    N2: TMenuItem;
    S1: TMenuItem;
    N3: TMenuItem;
    E1: TMenuItem;
    N4: TMenuItem;
    M1: TMenuItem;
    S2: TMenuItem;
    N1: TMenuItem;
    N5: TMenuItem;
    S3: TMenuItem;
    E2: TMenuItem;
    N6: TMenuItem;
    N7: TMenuItem;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    GroupBox1: TGroupBox;
    Label10: TLabel;
    cb_abortonviolation: TCheckBox;
    cb_abortonproblem: TCheckBox;
    cb_transliterate: TCheckBox;
    Edit1: TEdit;
    GroupBox2: TGroupBox;
    cb_sourcereadonly: TCheckBox;
    cb_sourceexclusive: TCheckBox;
    cb_backuptables: TCheckBox;
    cb_usemappings: TCheckBox;
    cb_typecast: TCheckBox;
    Table: TTable;
    BatchMove: TBatchMove;
    Table2: TTable;
    DataSource1: TDataSource;
    DataSource2: TDataSource;
    S4: TMenuItem;
    TabSheet4: TTabSheet;
    Label15: TLabel;
    Memo1: TMemo;
    eb_sourcekey: TEdit;
    eb_destinationkey: TEdit;
    Label23: TLabel;
    Label24: TLabel;
    Label12: TLabel;
    Label14: TLabel;
    Label17: TLabel;
    eb_destinationpath: TEdit;
    eb_destinationtablename: TEdit;
    Edit7: TEdit;
    Label11: TLabel;
    Label13: TLabel;
    Label16: TLabel;
    eb_sourcepath: TEdit;
    eb_sourcetablename: TEdit;
    Edit6: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    DatabaseListbox: TListBox;
    TableListbox: TListBox;
    FieldListbox: TListBox;
    IndexListbox: TListBox;
    DatabaseListbox2: TListBox;
    TableListbox2: TListBox;
    FieldListbox2: TListBox;
    IndexListbox2: TListBox;
    map: TStringGrid;
    GroupBox3: TGroupBox;
    Label21: TLabel;
    Label22: TLabel;
    eb_netfiledir: TEdit;
    eb_privatedir: TEdit;
    GroupBox5: TGroupBox;
    Label18: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    eb_changedTable: TEdit;
    eb_problemtable: TEdit;
    eb_violationtable: TEdit;
    RadioGroup1: TRadioGroup;
    cb_requestlive: TCheckBox;
    OpenDialog1: TOpenDialog;
    RadioButton1: TRadioButton;
    RadioButton2: TRadioButton;
    N8: TMenuItem;
    C1: TMenuItem;
    RadioButton3: TRadioButton;
    CreateAlias1: TMenuItem;
    Reports1: TMenuItem;
    Procedure TableListboxClick(Sender: TObject);
    Procedure DatabaseListboxClick(Sender: TObject);
    Procedure FormCreate(Sender: TObject);
    Procedure SpeedButton1Click(Sender: TObject);
    Procedure FieldListboxDblClick(Sender: TObject);
    Procedure FieldListbox2DblClick(Sender: TObject);
    Procedure SpeedButton2Click(Sender: TObject);
    Procedure DatabaseListbox2Click(Sender: TObject);
    Procedure TableListbox2Click(Sender: TObject);
    Procedure SpeedButton10Click(Sender: TObject);
    Procedure SpeedButton5Click(Sender: TObject);
    Procedure SpeedButton3Click(Sender: TObject);
    Procedure SpeedButton4Click(Sender: TObject);
    Procedure SpeedButton6Click(Sender: TObject);
    Procedure SpeedButton7Click(Sender: TObject);
    Procedure SpeedButton8Click(Sender: TObject);
    Procedure IndexListboxClick(Sender: TObject);
    Procedure IndexListbox2Click(Sender: TObject);
    Procedure RadioGroup1Click(Sender: TObject);
    Procedure E1Click(Sender: TObject);
    Procedure closedatabases;
    Procedure Batchmovedata;
    Procedure Searchmovedata;
    Procedure backupdestination;
    Procedure SQLExecute;
    Procedure automapfields;
    Procedure clearmappings;
    Procedure SpeedButton9Click(Sender: TObject);
    Procedure S4Click(Sender: TObject);
    Procedure E2Click(Sender: TObject);
    Procedure M1Click(Sender: TObject);
    Procedure S2Click(Sender: TObject);
    Procedure eb_sourcepathExit(Sender: TObject);
    Procedure eb_sourcetablenameExit(Sender: TObject);
    Procedure eb_destinationtablenameExit(Sender: TObject);
    Procedure eb_destinationpathExit(Sender: TObject);
    Procedure N2Click(Sender: TObject);
    Procedure S1Click(Sender: TObject);
    Procedure mapKeyDown(Sender: TObject; Var Key: Word;
    Shift: TShiftState);
    Procedure C1Click(Sender: TObject);
    Procedure eb_netfiledirKeyDown(Sender: TObject; Var Key: Word;
    Shift: TShiftState);
    Procedure eb_privatedirKeyDown(Sender: TObject; Var Key: Word;
    Shift: TShiftState);
    
  End;
    
Var
  maindlg: Tmaindlg;
  srcrow, destrow: integer;
  sqlactive: boolean;
  
Implementation

{$R *.DFM}
Procedure tmaindlg.backupdestination;
Begin
  {}
End;

Procedure tmaindlg.searchmovedata;

{-----------------------------------------------------------------------------------------}
{This is a custom move function that will use the keyed fields specified and match up all }
{fields that are indicated leaving the rest alone.                                        }
{-----------------------------------------------------------------------------------------}

Var
  endloop , loop: integer;
  key1, key2: String;
Begin
  screen.cursor := crhourglass;
  If cb_backuptables.checked Then backupdestination;
  {setup source and destination info}
  {---------------------------}
  {if (sql.active) then begin }
  {batchmove.source:= SQL;    }
  {sql.active := false;       }
  {sql.sql.clear;             }
  {sql.sql := memo1.lines;    }
  {sql.active := true;        }
  {end;                       }
  {---------------------------}
  source.active := false;
  source.databasename := eb_sourcepath.text;
  source.tablename := eb_sourcetablename.text;
  source.active := true;
  destination.active := false;
  destination.databasename := eb_destinationpath.text;
  destination.tablename := eb_destinationtablename.text;
  destination.active := true;
  source.first;
  destination.first;
  key1 := eb_sourcekey.text;
  key2 := eb_destinationkey.text;
  If Not radiobutton3.checked Then Begin
    Repeat
      Repeat
        If ((radiobutton1.checked) And (source.fieldbyname(key1).asstring = destination.fieldbyname(key2).asstring)) Or
        ((radiobutton2.checked) And (source.fieldbyname(key1).asinteger = destination.fieldbyname(key2).asinteger)) Then Begin
          {we have an Exact match matching key}
          destination.edit;
          For loop := 1 To map.rowcount Do Begin
            If (map.cells[1, loop] <> '') And (map.cells[0, loop] <> '') Then
              destination.fieldbyname(map.cells[1, loop]).asstring := source.fieldbyname(map.cells[0, loop]).asstring;
          End;
          destination.post;
        End;
        destination.next;
      Until destination.eof;
      destination.first;
      source.next;
    Until source.eof;
  End
  Else Begin
    {this is an append not an update}
    Repeat
      destination.append;
      For loop := 1 To map.rowcount Do Begin
        If (map.cells[1, loop] <> '') And (map.cells[0, loop] <> '') Then
          destination.fieldbyname(map.cells[1, loop]).asstring := source.fieldbyname(map.cells[0, loop]).asstring;
      End;
      destination.post;
      source.next;
    Until source.eof;
  End;
  screen.cursor := crdefault;
End;





Procedure tmaindlg.clearmappings;
Var
  loop: integer;
Begin
  For loop := 1 To map.rowcount Do Begin
    map.cells[0, loop] := '';
    map.cells[1, loop] := '';
  End;
  map.rowcount := 2;
  map.cells[0, 0] := 'Source';
  map.cells[1, 0] := 'Destination';
  srcrow := 0;
  destrow := 0;
End;

Procedure tmaindlg.automapfields;
Var
  innerloop, loop: integer;
  ok: boolean;
  sstr, dstr: string;
Begin
  screen.cursor := crhourglass;
  {clear the map box}
  For loop := 1 To map.rowcount Do Begin
    map.cells[0, loop] := '';
    map.cells[1, loop] := '';
  End;
  map.rowcount := 2;
  map.cells[0, 0] := 'Source';
  map.cells[1, 0] := 'Destination';
  srcrow := 0;
  destrow := 0;
  {}
  If (fieldlistbox.items.count <> 0) And
  (fieldlistbox2.items.count <> 0) Then Begin
    ok := false;
    loop := 0;
    innerloop := 0;
    Repeat
      sstr := fieldlistbox.items[loop];
      Repeat
        dstr := fieldlistbox2.items[innerloop];
        If sysutils.uppercase(sstr) = sysutils.uppercase(dstr) Then ok := true Else ok := false;
        If ok Then Begin
          inc(srcrow);
          If map.rowcount < srcrow + 1 Then map.rowcount := map.rowcount + 1;
          map.refresh;
          map.cells[0, srcrow] := fieldlistbox.items[loop];
          inc(destrow);
          If map.rowcount < destrow + 1 Then map.rowcount := map.rowcount + 1;
          map.refresh;
          map.cells[1, destrow] := fieldlistbox2.items[innerloop];
        End;
        inc(innerloop);
      Until innerloop = fieldlistbox2.items.count - 1;
      innerloop := 0;
      inc(loop);
    Until loop = fieldlistbox.items.count - 1;
  End;
  screen.cursor := crdefault;
End;

Procedure tmaindlg.SQLExecute;
Var
  loop: integer;
Begin
  screen.cursor := crhourglass;
  Try
    sql.active := false;
    sql.requestlive := cb_requestlive.checked;
    sql.databasename := eb_sourcepath.text;
    sql.sql.clear;
    sql.sql := memo1.lines;
    sql.active := true;
    FieldListbox.Clear;
    databaselistbox.clear;
    tablelistbox.clear;
    indexlistbox.clear;
    If sql.fieldcount <> 0 Then
      For loop := 0 To sql.fieldcount - 1 Do
        fieldlistbox.items.add(sql.fields[loop].displaylabel);
      batchmove.source := SQL;
    Finally
      screen.cursor := crdefault;
    End;
  End;
Procedure tmaindlg.batchmovedata;
Var
  endloop , loop: integer;
Begin
  screen.cursor := crhourglass;
  If cb_backuptables.checked Then Begin
    {------------------------------------------------------}
    {Make a backup of the Destination database             }
    {1. determine if the database is a table or a Database }
    {------------------------------------------------------}
  End;
  {setup batchmove component}
  batchmove.changedtablename := eb_changedtable.text;
  batchmove.keyvioltablename := eb_violationtable.text;
  batchmove.problemtablename := eb_problemtable.text;
  batchmove.abortonkeyviol := cb_abortonviolation.checked;
  batchmove.abortonproblem := cb_abortonproblem.checked;
  batchmove.transliterate  := cb_transliterate.checked;
  {move data to batchmove component}
  batchmove.mappings.clear;
  If srcrow >= destrow Then endloop := srcrow Else endloop := destrow;
  For loop := 1 To endloop Do Begin
    With batchmove Do Begin
      mappings.add(map.cells[1, loop] + '=' + map.cells[0, loop]);
    End;
  End;
  {setup source and destination info}
  If (sql.active) Then Begin
    batchmove.source := SQL;
    sql.active := false;
    sql.sql.clear;
    sql.sql := memo1.lines;
    sql.active := true;
  End
  Else Begin
    batchmove.source := source;
    source.active := false;
    source.databasename := eb_sourcepath.text;
    source.tablename := eb_sourcetablename.text;
    source.active := true;
  End;
  destination.active := false;
  destination.databasename := eb_destinationpath.text;
  destination.tablename := eb_destinationtablename.text;
  destination.active := true;
  batchmove.execute;
  screen.cursor := crdefault;
  edit1.text := inttostr(batchmove.recordcount);
End;

Procedure tmaindlg.closedatabases;
Begin
  SpeedButton9Click(nil);
  source.active := false;
  destination.active := false;
  sql.active := false;
  Session.GetDatabaseNames(DatabaseListbox.Items);
  Session.GetDatabaseNames(DatabaseListbox2.Items);
End;

Procedure Tmaindlg.TableListboxClick(Sender: TObject);
Begin
  FieldListbox.Clear;
  IndexListbox.Clear;
  Table.DatabaseName := DatabaseListbox.Items[DatabaseListbox.ItemIndex];
  table.readonly := cb_sourcereadonly.checked;
  table.exclusive := cb_sourceexclusive.checked;
  Table.TableName := TableListbox.Items[TableListbox.ItemIndex];
  Table.GetFieldNames(FieldListbox.Items);
  Table.GetIndexNames(IndexListbox.Items);
  If tablelistbox.itemindex <> - 1 Then Begin
    eb_sourcetablename.text := tablelistbox.items[tablelistbox.itemindex];
  End;
  edit6.text := '';
End;

Procedure Tmaindlg.DatabaseListboxClick(Sender: TObject);
Begin
  TableListbox.Clear;
  FieldListbox.Clear;
  IndexListbox.Clear;
  If sql.active Then sqlexecute; {turn sql off}
  Session.GetTableNames(DatabaseListbox.Items[DatabaseListbox.ItemIndex],
  '', True, False, TableListbox.Items);
  If databaselistbox.itemindex <> - 1 Then Begin
    eb_sourcepath.text := databaselistbox.items[databaselistbox.itemindex];
  End;
  eb_sourcetablename.text := '';
End;

Procedure Tmaindlg.FormCreate(Sender: TObject);
Begin
  sql.active := false;
  session.netfiledir := eb_netfiledir.text;
  eb_privatedir.text :=  extractfilepath(paramstr(0));
  session.privatedir := eb_privatedir.text;
  Session.GetDatabaseNames(DatabaseListbox.Items);
  Session.GetDatabaseNames(DatabaseListbox2.Items);
  map.cells[0, 0] := 'Source';
  map.cells[1, 0] := 'Destination';
  srcrow := 0;
  destrow := 0;
End;

Procedure Tmaindlg.SpeedButton1Click(Sender: TObject);
Begin
  If fieldlistbox.itemindex <> - 1 Then Begin
    inc(srcrow);
    If map.rowcount < srcrow + 1 Then Begin
      map.cells[0, map.rowcount] := '';
      map.cells[1, map.rowcount] := '';
      map.rowcount := map.rowcount + 1;
    End;
    map.refresh;
    map.cells[0, srcrow] := fieldlistbox.items[fieldlistbox.itemindex];
  End;
End;

Procedure Tmaindlg.FieldListboxDblClick(Sender: TObject);
Begin
  speedbutton1click(sender);
End;

Procedure Tmaindlg.FieldListbox2DblClick(Sender: TObject);
Begin
  speedbutton2click(sender);
End;

Procedure Tmaindlg.SpeedButton2Click(Sender: TObject);
Begin
  If fieldlistbox2.itemindex <> - 1 Then Begin
    inc(destrow);
    If map.rowcount < destrow + 1 Then Begin
      map.rowcount := map.rowcount + 1;
      map.cells[0, map.rowcount] := '';
      map.cells[1, map.rowcount] := '';
    End;
    map.refresh;
    map.cells[1, destrow] := fieldlistbox2.items[fieldlistbox2.itemindex];
  End;
End;

Procedure Tmaindlg.DatabaseListbox2Click(Sender: TObject);
Begin
  TableListbox2.Clear;
  FieldListbox2.Clear;
  IndexListbox2.Clear;
  Session.GetTableNames(DatabaseListbox2.Items[DatabaseListbox2.ItemIndex],
  '', True, False, TableListbox2.Items);
  If databaselistbox2.itemindex <> - 1 Then Begin
    eb_destinationpath.text := databaselistbox2.items[databaselistbox2.itemindex];
  End;
  eb_destinationtablename.text := '';
End;

Procedure Tmaindlg.TableListbox2Click(Sender: TObject);
Begin
  FieldListbox2.Clear;
  IndexListbox2.Clear;
  Table2.DatabaseName := DatabaseListbox2.Items[DatabaseListbox2.ItemIndex];
  Table2.TableName := TableListbox2.Items[TableListbox2.ItemIndex];
  Table2.GetFieldNames(FieldListbox2.Items);
  Table2.GetIndexNames(IndexListbox2.Items);
  If tablelistbox2.itemindex <> - 1 Then Begin
    eb_destinationtablename.text := tablelistbox2.items[tablelistbox2.itemindex];
  End;
  edit7.text := '';
End;

Procedure Tmaindlg.SpeedButton10Click(Sender: TObject);
Begin
  automapfields;
End;
Procedure Tmaindlg.SpeedButton5Click(Sender: TObject);
Begin
  If tablelistbox.itemindex <> - 1 Then Begin
    eb_sourcetablename.text := tablelistbox.items[tablelistbox.itemindex];
  End;
End;

Procedure Tmaindlg.SpeedButton3Click(Sender: TObject);
Begin
  If databaselistbox.itemindex <> - 1 Then Begin
    eb_sourcepath.text := databaselistbox.items[databaselistbox.itemindex];
  End;
End;

Procedure Tmaindlg.SpeedButton4Click(Sender: TObject);
Begin
  If databaselistbox2.itemindex <> - 1 Then Begin
    eb_destinationpath.text := databaselistbox2.items[databaselistbox2.itemindex];
  End;
End;

Procedure Tmaindlg.SpeedButton6Click(Sender: TObject);
Begin
  If tablelistbox2.itemindex <> - 1 Then Begin
    eb_destinationtablename.text := tablelistbox2.items[tablelistbox2.itemindex];
  End;
End;

Procedure Tmaindlg.SpeedButton7Click(Sender: TObject);
Begin
  If indexlistbox.itemindex <> - 1 Then Begin
    edit6.text := indexlistbox.items[indexlistbox.itemindex];
  End;
End;

Procedure Tmaindlg.SpeedButton8Click(Sender: TObject);
Begin
  If indexlistbox2.itemindex <> - 1 Then Begin
    edit7.text := indexlistbox2.items[indexlistbox2.itemindex];
  End;
End;

Procedure Tmaindlg.IndexListboxClick(Sender: TObject);
Begin
  If indexlistbox.itemindex <> - 1 Then Begin
    edit6.text := indexlistbox.items[indexlistbox.itemindex];
  End;
End;

Procedure Tmaindlg.IndexListbox2Click(Sender: TObject);
Begin
  If indexlistbox2.itemindex <> - 1 Then Begin
    edit7.text := indexlistbox2.items[indexlistbox2.itemindex];
  End;
End;

Procedure Tmaindlg.RadioGroup1Click(Sender: TObject);
Begin
  Case radiogroup1.itemindex Of
    0: Begin
      batchmove.mode := batappend;
    End;
    1: Begin
      batchmove.mode := batappendupdate;
    End;
    2: Begin
      batchmove.mode := batcopy;
    End;
    3: Begin
      batchmove.mode := batdelete;
    End;
    4: Begin
      batchmove.mode := batupdate;
    End;
  End;
End;

Procedure Tmaindlg.E1Click(Sender: TObject);
Begin
  closedatabases;
  close;
End;

Procedure Tmaindlg.SpeedButton9Click(Sender: TObject);
Begin
  clearmappings;
End;

Procedure Tmaindlg.S4Click(Sender: TObject);
Begin
  tabledlg.show;
End;

Procedure Tmaindlg.E2Click(Sender: TObject);
Begin
  sqlexecute;
End;

Procedure Tmaindlg.M1Click(Sender: TObject);
Begin
  batchmovedata;
End;

Procedure Tmaindlg.S2Click(Sender: TObject);
Begin
  searchmovedata;
End;

Procedure Tmaindlg.eb_sourcepathExit(Sender: TObject);
Begin
  source.databasename := eb_sourcepath.text;
End;

Procedure Tmaindlg.eb_sourcetablenameExit(Sender: TObject);
Var
  loop: integer;
Begin
  source.tablename := eb_sourcetablename.text;
End;

Procedure Tmaindlg.eb_destinationtablenameExit(Sender: TObject);
Var
  loop: integer;
Begin
  destination.tablename := eb_destinationtablename.text;
End;

Procedure Tmaindlg.eb_destinationpathExit(Sender: TObject);
Begin
  destination.databasename := eb_destinationpath.text;
End;

Procedure Tmaindlg.N2Click(Sender: TObject);
Var
  loop: integer;
Begin
  opendialog1.title := 'Select Source Database';
  If opendialog1.execute Then Begin
    eb_sourcepath.text := extractfilepath(opendialog1.filename);
    eb_sourcetablename.text := extractfilename(opendialog1.filename);
    source.close;
    source.databasename := eb_sourcepath.text;
    source.tablename := eb_sourcetablename.text;
    fieldlistbox.clear;
    source.open;
    If source.fieldcount <> 0 Then
      For loop := 0 To source.fieldcount - 1 Do
        fieldlistbox.items.add(source.fields[loop].displaylabel);
    End;
  End;
Procedure Tmaindlg.S1Click(Sender: TObject);
Var
  loop: integer;
Begin
  opendialog1.title := 'Select Destination Database';
  If opendialog1.execute Then Begin
    eb_destinationpath.text := extractfilepath(opendialog1.filename);
    eb_destinationtablename.text := extractfilename(opendialog1.filename);
    destination.close;
    destination.databasename := eb_destinationpath.text;
    destination.tablename := eb_destinationtablename.text;
    fieldlistbox2.clear;
    destination.open;
    If destination.fieldcount <> 0 Then
      For loop := 0 To destination.fieldcount - 1 Do
        fieldlistbox2.items.add(destination.fields[loop].displaylabel);
    End;
  End;
Procedure Tmaindlg.mapKeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Begin
  If ord(key) = 46 Then Begin
    {delete key pressed}
    map.cells[0, map.row] := '';
    map.cells[1, map.row] := '';
  End;
End;

Procedure Tmaindlg.C1Click(Sender: TObject);
Begin
  closedatabases;
  clearmappings;
  tablelistbox.clear;
  tablelistbox2.clear;
  fieldlistbox.clear;
  fieldlistbox2.clear;
  indexlistbox.clear;
  indexlistbox2.clear;
End;

Procedure Tmaindlg.eb_netfiledirKeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Begin
  If key = 13 Then session.netfiledir := eb_netfiledir.text;
End;

Procedure Tmaindlg.eb_privatedirKeyDown(Sender: TObject; Var Key: Word;
Shift: TShiftState);
Begin
  If key = 13 Then session.privatedir := eb_privatedir.text;
End;

End.

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now