FormView & SqlDataSource

G

Guest

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?

Thanks,

Victor
 
S

Steven Cheng[MSFT]

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)
{
try
{
FormView1.InsertItem(true);
}
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 ...


Regards,

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! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

FormView, SqlDataSource and handling exceptions 4
FormView 0
FormView 3
SqlDataSource identity 1
FormView 0
Formview and Sql Error Trapping and Page Validation... 4
FormView > Edit 1
FormView disappears 2

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top