Codeunit to update consolidated table

my problem is that i have to update my consolidated table using a header form which contains a update button that update button is pressed the data which is in that form is updated to my table consolidated .

i have to design a codeunit for this but when i am doing this a run time error comes “the consolidated table already contains the entry no” with this message.

please help me its in dynamic nav 2009 r2 classic client

I guess there is some issue in assigning Primary Key to Consolidated table. You can recheck your code.

my consolidated table contains entry no as primary key which an auto increment field like serial no.

SalesHeaderL.COPY(SalesHeaderP);
SaleslineL.SETRANGE(SaleslineL.“Bill No”,SalesHeaderL.“Bill No.”);
IF SaleslineL.FINDSET THEN
REPEAT
//ConsolidateG.“Entry No.” := ;
ConsolidateG.“Cust No.” := SalesHeaderL.“Cust No.”;
ConsolidateG.“Bill No.” := SaleslineL.“Bill No”;
ConsolidateG.“Item No.” := SaleslineL.“Item No.” ;
ConsolidateG.Quantity := SaleslineL.Quantity ;
ConsolidateG.Rate := SaleslineL.Rate;
ConsolidateG.Amount := SaleslineL.Amount;
ConsolidateG.“Other Charges” := SaleslineL.“Other charges”;
ConsolidateG.INSERT;
UNTIL SaleslineL.NEXT=0;

this is my codeunit which i have made and now can u please help me …

Try using ConsolidateG.INSERT(TRUE);

still getting the same error …please help me with other options to correct it

Try

SalesHeaderL.COPY(SalesHeaderP);
SaleslineL.SETRANGE(SaleslineL.“Bill No”,SalesHeaderL.“Bill No.”);
IF SaleslineL.FINDSET THEN
REPEAT
//ConsolidateG.“Entry No.” := ;
ConsolidateG.INIT;
ConsolidateG.“Cust No.” := SalesHeaderL.“Cust No.”;
ConsolidateG.“Bill No.” := SaleslineL.“Bill No”;
ConsolidateG.“Item No.” := SaleslineL.“Item No.” ;
ConsolidateG.Quantity := SaleslineL.Quantity ;
ConsolidateG.Rate := SaleslineL.Rate;
ConsolidateG.Amount := SaleslineL.Amount;
ConsolidateG.“Other Charges” := SaleslineL.“Other charges”;
ConsolidateG.INSERT(TRUE);
UNTIL SaleslineL.NEXT=0;

Check the primary key .I think it is Entry no field is primary key
You need to increment the Entry no field during inserting record.

As you mentioned Entry No. is a AutoIncrement field.
you need to assign 0 to it before Insert to work.
write below code after Init statement
ConsolidateG.“Entry No.” := 0;

That also not working still it coming with the same error.

activate the debugger and check whether you are getting error from where exactly.

when i am removing the entry no field from the table and then setting bil no and item no as key o am getting the data updated but when i am using entry no field i am getting that error

Is it showing any entry no. in error?
Probably it is resetting as you are changing the Primary key.
Delete the data from table, if it is test db, and start doing with above code again.

yes it is a test db and i am deleting the data all the time when i am running again nd again but still the same error comes "the entry no. 2 already contained in the table ".

Check with the following link.
msdn.microsoft.com/…/dd339035.aspx