Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 7 of 7 total
Thread copy records
Mon, Feb 11 2008 5:50 PMPermanent Link

Peter van Mierlo
hi

I have 5 tables, called (oke..are dutch names) :
- naw (fields naw_ID)
- function (field functionID, functionName)
- items (field itemID, itemName, itemCount)
- functionItems (fields FI_itemID, FI_functionID)
- nawItems (fields nawItems_nawID, nawItems_itemID, nawItems_count)

The table functionItems contains for a function one or more items, based on the tables function and items.
Within a guest registrations screen the user chooses a function for a person and sees which items belong
to this function. Because in this case the items are based on a function. Now i need to copy the items,
which are belonging to this function to a separate table, this is the table nawItems.

When there are 5 items for a specific function then must 5 records be copied to the table nawItems.
There's a unique index on this table based on the field nawItem_nawID + nawItem_itemID to prevent
copy the same value several times for the same person.

For some reason not all 5 records are copied, but in this case only 3, i deleted the index to be sure
it's not the index which causes the problem . i can't figure out where i'm going wrong. I uses the code
also for selecting records in one dbgrid and copy them to a second dbgrid, in that case the code
after the // is added extra.

Any idea how to solve this problem for copying records


I use the followin code :

procedure TdmTables.NawItemsAppend;
var
 i : integer;
begin
 i := dmTables.qry_functionItems.RecordCount;
 if i > 0 then begin
    with dmTables.ds_nawItems.DataSet do begin
      for i := 0 to dmTables.qry_itemBYuitgifte.RecordCount-1 do begin
        //// GotoBookmark(Pointer(SMDBGrid_items.SelectedRows.Items[i]));    // extra code when using it on a dbgrid
        dmTables.qry_nawItems.Append;
        dmTables.qry_nawItems.FieldByName('nawItem_nawID').value:=dmTables.qry_guest.fieldbyname('naw_id').value;
        dmTables.qry_nawItems.FieldByName('nawItem_itemID').Value:=dmTables.qry_functionItems.FieldByName('functionItem_itemID').Value;
      try
         dmTables.qry_nawItems.post;
      except
         dmTables.qry_nawItems.Cancel;
      end;
    end;
 end;
   end;
end;



Mon, Feb 11 2008 6:05 PMPermanent Link

"Robert"

"Peter van Mierlo" <p.mierlo@planet.nl> wrote in message
news:E4C8AC91-E7CD-449F-A525-5A1B2855E0C9@news.elevatesoft.com...
>       try
>          dmTables.qry_nawItems.post;
>       except
>          dmTables.qry_nawItems.Cancel; ???????
>       end;

I would start by finding out if you are getting an exception. This code IMO
is pretty bad, when you get a posting exception you just want to cancel and
keep going?

Robert

Mon, Feb 11 2008 6:33 PMPermanent Link

Peter van Mierlo
Hi Robert,

I used the code from a earlier post (http://www.elevatesoft.com/scripts/newsgrp.dll?action=searchopenmsg&group=5&msg=60249&keywords=dbgrid*#msg60249)
where i select some records in the left dbgrid, hit a button an copy them to the right dbgrid. In that case i also needed to prevent double records and did check
on the onposterror, but was suggested to delete the onposterror.

i tried several option for copying the records, but can't figure out what's the corerct solution
or how to do it with the correct code. I anyone has some suggestions or sample code
i would be thankfull.





"Robert" <ngsemail2005withoutthis@yahoo.com.ar> wrote:


"Peter van Mierlo" <p.mierlo@planet.nl> wrote in message
news:E4C8AC91-E7CD-449F-A525-5A1B2855E0C9@news.elevatesoft.com...
>       try
>          dmTables.qry_nawItems.post;
>       except
>          dmTables.qry_nawItems.Cancel; ???????
>       end;

I would start by finding out if you are getting an exception. This code IMO
is pretty bad, when you get a posting exception you just want to cancel and
keep going?

Robert

Tue, Feb 12 2008 3:08 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Peter


It may just be me but I can't see anything that moves to the next record for dmTables.qry_guest

Roy Lambert
Tue, Feb 12 2008 2:25 PMPermanent Link

Peter van Mierlo
hi Roy,

thats correct but can't figure out WHERE to put the next, because
i can't get it working propertly...is there some other code i can use ?

Roy Lambert <roy.lambert@skynet.co.uk> wrote:

Peter


It may just be me but I can't see anything that moves to the next record for dmTables.qry_guest

Roy Lambert
Wed, Feb 13 2008 2:18 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Peter


You should add the next just after the try..except block. If that doesn't work can you post an example to the binaries (source and tables) and I'll sort it out for you.


Roy Lambert
Wed, Feb 13 2008 1:38 PMPermanent Link

Peter van Mierlo
Hi Roy,

Well..after a couple of hours i figured it out for getting it working, with the following code.
Maybe it's not the best code, but it's working ....thanks again


procedure TdmTables.NawItemsToevoegen;
var
 i : integer;
begin
 if dmTables.qry_itemBYnaw.recordCount > 0 then begin
    with dmTables.ds_itemBYnaw.DataSet do begin
      for i := 0 to dmTables.qry_itemBYnaw.RecordCount-1 do begin
        dmTables.qry_itemBYgast.Append;
        dmTables.qry_itemBYgast.FieldByName('nawItem_nawID').value:=dmTables.qry_gast.fieldbyname('naw_id').value;
        dmTables.qry_itemBYgast.FieldByName('nawitem_functieID').Value:=dmTables.qry_gast.FieldByName('naw_functieID').Value;
        dmTables.qry_itemBYgast.FieldByName('nawItem_itemID').Value:=dmTables.qry_itemBYnaw.FieldByName('functieitem_itemID').Value;
        dmTables.qry_itemBYgast.FieldByName('nawitem_itemAantal').Value:=dmTables.qry_itemBYnaw.FieldByName('functieitem_showItemAantal').Value;
      try
         dmTables.qry_itemBYgast.post;
      except
         dmTables.qry_itemBYgast.Cancel;
      end;
      dmTables.qry_itemBYnaw.next;
    end;
   end;
 end;
end;



Roy Lambert <roy.lambert@skynet.co.uk> wrote:

Peter


You should add the next just after the try..except block. If that doesn't work can you post an example to the binaries (source and tables) and I'll sort it out for you.


Roy Lambert
Image