locked
Exception Handling Using Generated INSERT Statement RRS feed

  • Question

  • User-180914566 posted

    Hi,

    I have a DetailsView on my web page and I'd like to use the automatically generated INSERT statement found in the advanced settings of my DataSource configuration.

    I'm wondering where I should write my code to handle exceptions such as Primary Key Violation, etc...

    So far I've only been able to find a place to handle exceptions if I write my INSERT statement manually.  However, I'd like to avoid doing so.

    Is there a way of using the automatically generated INSERT and handling exceptions?  If so, where?

    Thanks in advance for any feedback.

    Friday, July 12, 2013 10:17 AM

Answers

  • User-1716253493 posted
    Check it by SELECT COUNT(*) WHERE ID=@userinput
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 12, 2013 12:45 PM

All replies

  • User-1716253493 posted
    In your insert command don't include the primary key (autoincreament). Set is identity to yes in the field (sql) or set AutoNumber (access).
    Friday, July 12, 2013 10:58 AM
  • User-180914566 posted

    I need the user to be able to enter the primary key on insert.  The exception I'd like to handle is if the primary key already exists, the user would then be prompted to check again and correct the key.

    Thanks for your response.

    Friday, July 12, 2013 11:07 AM
  • User-1716253493 posted
    Check it by SELECT COUNT(*) WHERE ID=@userinput
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 12, 2013 12:45 PM