How do I check for errors after doing an insert on a database file?

Posted on 2009-02-19
Last Modified: 2012-05-06
I have created a program that allows the user to enter data on a form and when they click the submit button, it will call my subroutine to add the data to a database.  I have a sqldatasource called ds1 & the insert command calls a stored procedure.  The button click calls ds1.insert and I want to do some error checking to make sure the insert was successful.  If it was successful, then I want to send a message to let the user know that it's been successful.  I'm assuming that I can use the try...catch method but really don't know how to use this properly.  Any help is appreciated!!!
Question by:mmtcunningham1
    LVL 11

    Accepted Solution

       'Display success message
    Catch ex As Exception
       'Display error message
    End Try
    LVL 4

    Assisted Solution

    On the code behind use the sqldatasource's inserted event

    it should be something like this

        Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted
            If e.AffectedRows > 0 Then
                ClientScript.RegisterStartupScript(GetType(String), "success", "alert('SUCCESS!!!!');", True)
    'this is a javascript notice, you can put a label or whatever you'd like
            End If
        End Sub

    Open in new window


    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now