Try catch if record exist ASP.NET
<p>I'm trying to make a try/catch method to see if a record exist or not and generate an error messagebox if it does exist and if it not it will perform an insert. </p>

<p>Here's a sample of my code in insertMode:</p>

<p></p>

<pre><code>        ISBN:
        &lt;asp:TextBox ID="bookidTextBox" runat="server" Text='&lt;%# Bind("bookid") %&gt;' ToolTip="For the book ISBN please refer to the ISBN barcode usually located at the back of the book. A barcode reader is required." /&gt;

        &lt;asp:RequiredFieldValidator ID="RequesFieldValidator1" runat="server" ErrorMessage="* Required" ControlToValidate="bookidTextBox" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RequiredFieldValidator&gt;
        &lt;asp:RegularExpressionValidator ID="RegularExpressionValidator" runat="server" Display="Dynamic" ControlToValidate="bookidTextBox" ValidationExpression="^([\S\s]{10,13})$" ErrorMessage="Invalid ID/ISBN. Please try again" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RegularExpressionValidator&gt;
        &lt;br /&gt;

        Title:
        &lt;asp:TextBox ID="booktitleTextBox" runat="server" Text='&lt;%# Bind("booktitle") %&gt;' /&gt;
        &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* Required" ControlToValidate="booktitleTextBox" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RequiredFieldValidator&gt;
        &lt;br /&gt;

        Author's lastname:
        &lt;asp:TextBox ID="lastnameTextBox" runat="server" Text='&lt;%# Bind("lastname") %&gt;' /&gt;
        &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="* Required" ControlToValidate="lastnameTextBox" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RequiredFieldValidator&gt;
        &lt;br /&gt;

        Author's firstname:
        &lt;asp:TextBox ID="firstnameTextBox" runat="server" Text='&lt;%# Bind("firstname") %&gt;' /&gt;
        &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="* Required" ControlToValidate="firstnameTextBox" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RequiredFieldValidator&gt;
        &lt;br /&gt;

        Description:
        &lt;asp:TextBox ID="descriptionTextBox" runat="server" Height="150px" Width="300px" Text='&lt;%# Bind("description") %&gt;' /&gt;
        &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="* Required" ControlToValidate="descriptionTextBox" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RequiredFieldValidator&gt;
        &lt;br /&gt;

        Category:
        &lt;asp:DropDownList ID="DropDownList1" runat="server" 
            DataSourceID="categoryDataSource" DataTextField="name" 
            DataValueField="categoryid" SelectedValue='&lt;%# Bind("categoryid", "{0}") %&gt;' ToolTip="to add a new category please click the 'Manage Categories' menu"&gt;
        &lt;/asp:DropDownList&gt;

        &lt;asp:SqlDataSource ID="categoryDataSource" runat="server" 
            ConnectionString="&lt;%$ ConnectionStrings:LibrarySystemConnectionString %&gt;" 
            SelectCommand="SELECT [categoryid], [name] FROM [TblCategory]"&gt;
        &lt;/asp:SqlDataSource&gt;
        &lt;br /&gt;

        Quantity:
        &lt;asp:TextBox ID="quantityTextBox" runat="server" Text='&lt;%# Bind("quantity") %&gt;' /&gt;
        &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ErrorMessage="* Required" ControlToValidate="quantityTextBox" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RequiredFieldValidator&gt;
        &lt;asp:RangeValidator ID="RangeValidator" runat="server" ErrorMessage="Invalid inputs. Accept numbers only" ControlToValidate="quantityTextBox" MinimumValue="1" MaximumValue="50" ValidationGroup="InsertBook"&gt;
        &lt;/asp:RangeValidator&gt;
        &lt;br /&gt;

        &lt;asp:Button ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Add" ValidationGroup="InsertBook" PostBackUrl="~/Admin/ManageBooks.aspx"/&gt;

        &lt;asp:Button ID="InsertCancelButton" runat="server" 
            CausesValidation="False" CommandName="Cancel" Text="Cancel" /&gt;
</code></pre>

<p>Help would be much appreciated! Thanks in advance.</p>
