Solved

Help with Databases and multiple tables

Posted on 2001-06-21
4
143 Views
Last Modified: 2010-04-04
I haven't done much development with databases so I need some help.

I have two Access databases.   I need to look in the registry for a certain value
sLocale := jciRegsUtil.GetRegStringValue(TOOL, 'AimVer', 'LocaleName', '');
and search my Logistics table(Warehouse database) for records with sLocale in the Area field and add these records to my Contact table (Address database).
                   
I was going to try using the BatchMove component with the batAppend, but I believe that would append the entire second table.  Is there a way to use a select statement in a query and then the BatchMove to add the records from the select statement?

 Any help/code  would be appreciated :)

0
Comment
Question by:Tammi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:trex_fire
ID: 6215373
No but you can cycle through your query and insert your rows in your other table by putting another query with parameters.  Like:

MyQuery.Open;
While not MyQuery.EOf do begin
  InsertQuery.ParamByName('Param1').AsSomething := ...;
  InsertQuery.ParamByName('Param2').AsSomething := ...;
  ...
  InsertQuery.ExecSQL;
  MyQuery.Next;
end;

In InsertQuery, your SQL will look like this:

Insert into TableName
  (Field1,Field2,...)
  values (:Param1,:param2,...)

Hope it helps  ;)

T-Rex
0
 

Author Comment

by:Tammi
ID: 6220097
I actually got the BatchMove function to work by specifying my query as the source.  I'm still having problems getting the variable (Param) to work.  When I run the code below, I get a error "Parameter Param1 not found".  Any ideas??

begin
      qryArea := TQuery.Create(nil);
      qryArea.DatabaseName := 'dbnWarehouse';
      Param1 := TParam.Create(nil);
      qryArea.Params.AddParam(Param1);
      qryArea.ParamByName('Param1').Value := sLocale;
      qryArea.SQL.Text := 'SELECT * FROM Logistics WHERE Area = :Param1';
      qryArea.ExecSQL;
      BtchMvBradford.Source := qryArea;
      BtchMvBradford.Execute;
      qryArea.Free;
    end;

Thanks!!

Tammi
0
 
LVL 1

Accepted Solution

by:
trex_fire earned 100 total points
ID: 6221766
Ok would be easier to put your SQL in your TQuery and then look in Params property and adjust 'Param1' properties and Open / Close your query instead of ExecSQL... or just put your SQL before accessing your Params like:

begin
     qryArea := TQuery.Create(nil);
     qryArea.DatabaseName := 'dbnWarehouse';
     Param1 := TParam.Create(nil);
     qryArea.SQL.Text := 'SELECT * FROM Logistics WHERE Area = :Param1';
     qryArea.Params.AddParam(Param1);
     qryArea.ParamByName('Param1').Value := sLocale;
     qryArea.ExecSQL;
     BtchMvBradford.Source := qryArea;
     BtchMvBradford.Execute;
     qryArea.Free;
   end;


trex_fire@hotmail.com

T-Rex

 
0
 

Author Comment

by:Tammi
ID: 6225437
I ended up using the TQuery component and putting the SQL in the properties.  I had tried this previously but kept getting errors.  Discovered that I should have defined the DataSource, just the Database.  I used the following code:

begin
      qryArea.ParamByName('Param1').Value := sLocale;
      qryArea.Open;
      BtchMvBradford.Source := qryArea;
      BtchMvBradford.Execute;
      qryArea.Close;
      BtchMvBradford.Free;
    end;

Thanks for your help!!

Tammi
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 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