Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2009-02-19
Medium Priority
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

jmwheeler earned 1000 total points
ID: 23685998
   'Display success message
Catch ex As Exception
   'Display error message
End Try

Assisted Solution

siancell earned 1000 total points
ID: 23686052
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

578 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