0

I have a SqlDataSource and a GridView.

What I want to do is, while the query is executed (i.e. for inserting a data), then after the data has inserted successfully, it should appear a message sounds: "The data deleted successfully". I've solved it by using GridView1_RowDeleted method.

Now the problem is, I want to catch the error while the query is failed to executed. If the query has failed to execute, then it should appear a message: "The data failed to insert.".

How to do it? I don't have an idea about this.

Need your help guys.

Thanks a lot.

1 Answer 1

3

You should be able to add a handler for the relevant event: inserted, deleted. Then, in the handler look at the SqlDataSourceStatusEventArgs property Exception. If it's not null then an exception has occurred. For example if the selected command threw an exception:

protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
   if (e.Exception != null)
   {
       // handle the exception
   }
}

--

Sign up to request clarification or add additional context in comments.

1 Comment

hey it's worked!! :) . I've tried to change the handler become: Protected Sub SqlDataSource1_Updated(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Updated . Thanks a lot :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.