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

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!!!
Who is Participating?
   'Display success message
Catch ex As Exception
   'Display error message
End Try
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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.