By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,679 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,679 IT Pros & Developers. It's quick & easy.

FormView & SqlDataSource

P: n/a
Is there a way to handle when you're on insert mode on a formview and the
record you're about to save to the database already exist and insted you
rather update instead of inserting and getting an error of primary key?


May 22 '06 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Hi Victor,

Thank you for posting in the MSDN newsgroup.

As for the SqlDataSource control, so far it is still concentrating on data
displaying and updating. When there occurs error in the backend database,
the SqlDataSource control (ASP.NET application layer) will simply throw out
an exception. Since SqlDataSource control doesn't provide built-in events
for error handling, we need to do the exception handling through general
try....catch... block in the code path. And this will require us to
programmtically invoke the FormView's update method in order to control
the code path. e.g:

protected void Button1_Click(object sender, EventArgs e)
catch (Exception ex)
Response.Write("<br/>" + ex.ToString());

Or you can also consider using page's Page_error event, this event can
capture all the unhandled exceptions in the page's processing path. You can
redirect the user to a custom error/recovery page ...

Steven Cheng
Microsoft Online Community Support

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure!
(This posting is provided "AS IS", with no warranties, and confers no

May 23 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.