DBAsupport.com Forums - Powered by vBulletin
Results 1 to 8 of 8

Thread: unable to insert a new record in developer

  1. #1
    Join Date
    Jul 2002
    Posts
    24
    I am new to Developer 6i and i would like to learn it.


    I have 2 datablocks Dept & Emp. I need to insert data into forms, what is the best way to do that?

    I tried the following but i couldn't get it to work.

    im trying to insert data into forms, when using the toolbar keys i.e the insert record button it works fine but ive created my own button to insert data and it uses the following code:

    INSERT INTO Emp VALUES
    (:emp.empno,
    :emp.ename,
    :emp.job,
    :emp.mgr,
    :emp.hiredate,
    :emp.sal,
    :emp.comm,
    :emp.deptno);
    COMMIT;

    i used "when_button_bressed trigger" and when i press the button i get the following error:
    FRM-40735:when_button_bressed trigger raised unhadled exception ora-000001

    Any help.
    Thanks in advance.

  2. #2
    Join Date
    Jul 2002
    Posts
    9

    Wink

    Your when_button_pressed trigger was executed, but exists a duplicate key, verify primay key or unique key of your table data. The value of your primary key item of form exists in the table.


    if you write the exception when_dup_val_on_index eg:

    begin
    -- your code
    exception
    when dup_val_on_index then
    message("Duplicate Record"||:emp.empno||'-'||:emp.ename);
    end;

    then
    you can see the values of your duplicated record. and resolve your problem

    ---------------------------------------
    Silas - silas.silva@tecmind.com.br

  3. #3
    Join Date
    Jul 2002
    Posts
    24

    still unaple to insert a new record

    Silas, unfortunately, that didn't solve the prob. I wrote the following code but still getting the same error.

    begin
    INSERT INTO Emp VALUES
    (:emp.empno,
    :emp.ename,
    :emp.job,
    :emp.mgr,
    :emp.hiredate,
    :emp.sal,
    :emp.comm,
    :emp.deptno);
    COMMIT;
    exception
    when dup_val_on_index then
    message('Duplicate Record'||:emp.empno||'-'||:emp.ename);
    end;

  4. #4
    Join Date
    Aug 2002
    Posts
    56
    Try the when others exception handler. It will give you the exact message which is causing the error. try it:

    EXCEPTION
    WHEN OTHERS then
    clear_message;
    message(substr(sqlerrm, 1, 120));
    message(' ');

    After doing this you will be able to get the error message and work accordingly. See if this helps.

    Ciao

  5. #5
    Join Date
    Jun 2002
    Posts
    22
    If your block emp is table block ( you can query, edit , delete and update record-s) you do not need to write insert statement, just write

    begin
    commit;
    end;

    in your when_button_pressed trigger.


    If you block is not table block then do next:

    INSERT INTO Emp
    (empno,
    ename,
    job,
    mgr,
    hiredate,
    sal,
    comm,
    deptno)
    VALUES
    (:emp.empno,
    :emp.ename,
    :emp.job,
    :emp.mgr,
    :emp.hiredate,
    :emp.sal,
    :emp.comm,
    :emp.deptno);


    [Edited by Ao on 08-01-2002 at 05:03 AM]
    AleŇ°

  6. #6
    Join Date
    Aug 2001
    Location
    Manchester, UK
    Posts
    86
    Normally you should not use insert statements in WBP trigger. Also check if the items are on proper blocks. Is there any display item or non base table item defined on EMP block.

    When you say commit inside a trigger it commits the form for all the blocks. So if you can see deptno in the other datablock it will try to insert the same deptno again and so you are getting the unique constraint violated error.

    Just write commit_form; in WBP and it should solve the problem.
    -- Anurag.
    OCP Application Developer
    ---------------------------------------------------------
    "Be not afraid of growing slowly. Be afraid only of standing still."

  7. #7
    Join Date
    Aug 2002
    Posts
    56

    Normally you should not use insert statements in WBP trigger.

    This is an intresting remark made by you OCPIP. I have always wondered what the general practice is regarding this. I am working mostly on freelance basis and have been using inserts, update and delete statements in WBP triggers.

    I feel that it gives me much more control than letting forms do it. I guess this feeling arises from 1-2 really bad exp. after using a database block in forms where I had to redo everything from scratch as it seemed to go haywire.

    Anyways folks let me know what is the genral practice that is followed and what are the pros and cons of each (using forms pre_defined proc. to edit delete and create records or to use insert, update and delete statements by making the block a 'CONTROL BLOCK')!!

    Thanks

  8. #8
    Join Date
    Jul 2002
    Posts
    24
    Thank you guys for your help.
    I removed the insert statement and left the commit statement exactly like what OCPIP said.




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Click Here to Expand Forum to Full Width