Check update status in formviewhttp://forums.asp.net/t/1799841.aspx/1?Check+update+status+in+formviewWed, 09 May 2012 22:53:28 -040017998414964366http://forums.asp.net/p/1799841/4964366.aspx/1?Check+update+status+in+formviewCheck update status in formview <p>Hi,</p> <p>I have a formview that uses an object data source with insert and update methods specified. In update method I return a value (bool or int) to specify if updating database&nbsp;was successful or not. Is there any way I can check this value in ItemUpdated event of formview in order to display appropriate message to user?</p> 2012-05-03T19:22:46-04:004964461http://forums.asp.net/p/1799841/4964461.aspx/1?Re+Check+update+status+in+formviewRe: Check update status in formview <p>Instead &nbsp;of returning a value you can dolike this in ItemUpdated event of the formview &nbsp;to check whether data is updated successfully or not.</p> <p>protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e)<br> {<br> if (e.Exception != null)<br> {<br> lblError.Text = e.Exception.Message;<br> }<br> }</p> <p>Thanks</p> <p>Madhu</p> <p></p> <p></p> 2012-05-03T21:10:55-04:004964527http://forums.asp.net/p/1799841/4964527.aspx/1?Re+Check+update+status+in+formviewRe: Check update status in formview <p>This was my first option and I posted an issue about it but since I got no response, I thought I try this.</p> <p>This is the thread about using e.Exception:</p> <p><a href="http://forums.asp.net/t/1799785.aspx/1?FormView&#43;ItemUpdated&#43;problem">http://forums.asp.net/t/1799785.aspx/1?FormView&#43;ItemUpdated&#43;problem</a></p> 2012-05-03T23:39:35-04:004968786http://forums.asp.net/p/1799841/4968786.aspx/1?Re+Check+update+status+in+formviewRe: Check update status in formview <p>I have tried a sample without any problems based on your description in this post.</p> <p>Here are the sample.</p> <pre class="prettyprint">Default.aspx &lt;%@ Page Language=&quot;C#&quot; AutoEventWireup=&quot;true&quot; CodeFile=&quot;Default.aspx.cs&quot; Inherits=&quot;_Default&quot; %&gt; &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head runat=&quot;server&quot;&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt; &lt;div&gt; &lt;asp:FormView ID=&quot;FormView1&quot; runat=&quot;server&quot; DataKeyNames=&quot;CourseID&quot; DataSourceID=&quot;SqlDataSource1&quot; onitemupdated=&quot;FormView1_ItemUpdated&quot;&gt; &lt;EditItemTemplate&gt; CourseID: &lt;asp:Label ID=&quot;CourseIDLabel1&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;CourseID&quot;) %&gt;' /&gt; &lt;br /&gt; Title: &lt;asp:TextBox ID=&quot;TitleTextBox&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;Title&quot;) %&gt;' /&gt; &lt;br /&gt; Credits: &lt;asp:TextBox ID=&quot;CreditsTextBox&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;Credits&quot;) %&gt;' /&gt; &lt;br /&gt; DepartmentID: &lt;asp:TextBox ID=&quot;DepartmentIDTextBox&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;DepartmentID&quot;) %&gt;' /&gt; &lt;br /&gt; &lt;asp:LinkButton ID=&quot;UpdateButton&quot; runat=&quot;server&quot; CausesValidation=&quot;True&quot; CommandName=&quot;Update&quot; Text=&quot;Update&quot; /&gt; &amp;nbsp;&lt;asp:LinkButton ID=&quot;UpdateCancelButton&quot; runat=&quot;server&quot; CausesValidation=&quot;False&quot; CommandName=&quot;Cancel&quot; Text=&quot;Cancel&quot; /&gt; &lt;/EditItemTemplate&gt; &lt;InsertItemTemplate&gt; CourseID: &lt;asp:TextBox ID=&quot;CourseIDTextBox&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;CourseID&quot;) %&gt;' /&gt; &lt;br /&gt; Title: &lt;asp:TextBox ID=&quot;TitleTextBox&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;Title&quot;) %&gt;' /&gt; &lt;br /&gt; Credits: &lt;asp:TextBox ID=&quot;CreditsTextBox&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;Credits&quot;) %&gt;' /&gt; &lt;br /&gt; DepartmentID: &lt;asp:TextBox ID=&quot;DepartmentIDTextBox&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;DepartmentID&quot;) %&gt;' /&gt; &lt;br /&gt; &lt;asp:LinkButton ID=&quot;InsertButton&quot; runat=&quot;server&quot; CausesValidation=&quot;True&quot; CommandName=&quot;Insert&quot; Text=&quot;Insert&quot; /&gt; &amp;nbsp;&lt;asp:LinkButton ID=&quot;InsertCancelButton&quot; runat=&quot;server&quot; CausesValidation=&quot;False&quot; CommandName=&quot;Cancel&quot; Text=&quot;Cancel&quot; /&gt; &lt;/InsertItemTemplate&gt; &lt;ItemTemplate&gt; CourseID: &lt;asp:Label ID=&quot;CourseIDLabel&quot; runat=&quot;server&quot; Text='&lt;%# Eval(&quot;CourseID&quot;) %&gt;' /&gt; &lt;br /&gt; Title: &lt;asp:Label ID=&quot;TitleLabel&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;Title&quot;) %&gt;' /&gt; &lt;br /&gt; Credits: &lt;asp:Label ID=&quot;CreditsLabel&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;Credits&quot;) %&gt;' /&gt; &lt;br /&gt; DepartmentID: &lt;asp:Label ID=&quot;DepartmentIDLabel&quot; runat=&quot;server&quot; Text='&lt;%# Bind(&quot;DepartmentID&quot;) %&gt;' /&gt; &lt;br /&gt; &lt;asp:LinkButton ID=&quot;EditButton&quot; runat=&quot;server&quot; CausesValidation=&quot;False&quot; CommandName=&quot;Edit&quot; Text=&quot;Edit&quot; /&gt; &amp;nbsp;&lt;asp:LinkButton ID=&quot;DeleteButton&quot; runat=&quot;server&quot; CausesValidation=&quot;False&quot; CommandName=&quot;Delete&quot; Text=&quot;Delete&quot; /&gt; &amp;nbsp;&lt;asp:LinkButton ID=&quot;NewButton&quot; runat=&quot;server&quot; CausesValidation=&quot;False&quot; CommandName=&quot;New&quot; Text=&quot;New&quot; /&gt; &lt;/ItemTemplate&gt; &lt;/asp:FormView&gt; &lt;asp:SqlDataSource ID=&quot;SqlDataSource1&quot; runat=&quot;server&quot; ConflictDetection=&quot;CompareAllValues&quot; ConnectionString=&quot;&lt;%$ ConnectionStrings:SchoolConnectionString %&gt;&quot; DeleteCommand=&quot;DELETE FROM [Course] WHERE [CourseID] = @original_CourseID AND [Title] = @original_Title AND [Credits] = @original_Credits AND [DepartmentID] = @original_DepartmentID&quot; InsertCommand=&quot;INSERT INTO [Course] ([CourseID], [Title], [Credits], [DepartmentID]) VALUES (@CourseID, @Title, @Credits, @DepartmentID)&quot; OldValuesParameterFormatString=&quot;original_{0}&quot; SelectCommand=&quot;SELECT * FROM [Course]&quot; UpdateCommand=&quot;UPDATE [Course] SET [Title] = @Title, [Credits] = @Credits, [DepartmentID] = @DepartmentID WHERE [CourseID] = @original_CourseID AND [Title] = @original_Title AND [Credits] = @original_Credits AND [DepartmentID] = @original_DepartmentID&quot;&gt; &lt;DeleteParameters&gt; &lt;asp:Parameter Name=&quot;original_CourseID&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;original_Title&quot; Type=&quot;String&quot; /&gt; &lt;asp:Parameter Name=&quot;original_Credits&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;original_DepartmentID&quot; Type=&quot;Int32&quot; /&gt; &lt;/DeleteParameters&gt; &lt;InsertParameters&gt; &lt;asp:Parameter Name=&quot;CourseID&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;Title&quot; Type=&quot;String&quot; /&gt; &lt;asp:Parameter Name=&quot;Credits&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;DepartmentID&quot; Type=&quot;Int32&quot; /&gt; &lt;/InsertParameters&gt; &lt;UpdateParameters&gt; &lt;asp:Parameter Name=&quot;Title&quot; Type=&quot;String&quot; /&gt; &lt;asp:Parameter Name=&quot;Credits&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;DepartmentID&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;original_CourseID&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;original_Title&quot; Type=&quot;String&quot; /&gt; &lt;asp:Parameter Name=&quot;original_Credits&quot; Type=&quot;Int32&quot; /&gt; &lt;asp:Parameter Name=&quot;original_DepartmentID&quot; Type=&quot;Int32&quot; /&gt; &lt;/UpdateParameters&gt; &lt;/asp:SqlDataSource&gt; &lt;br /&gt; &lt;asp:Label ID=&quot;Label1&quot; runat=&quot;server&quot; Text=&quot;Label&quot;&gt;&lt;/asp:Label&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; Default.aspx.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e) { if (e.Exception == null) { if (e.AffectedRows == 1) { Label1.Text = &quot;Update successfully!&quot;; } else { Label1.Text = &quot;An error occurred during the update operation. &quot;; } } else { Label1.Text = e.Exception.Message; } } } //After updated, the Label can show Update successfully!</pre> <p></p> 2012-05-07T09:57:05-04:004973490http://forums.asp.net/p/1799841/4973490.aspx/1?Re+Check+update+status+in+formviewRe: Check update status in formview <p>Thanks for the reply.</p> <p>I am not using SQL but Oracle database (which I hate!) I think in SQL if SET NOCOUNT is OFF then it returns the number of rows updated otherwise it won't. Not sure if Oracle is casuing this But I have simiar structure as your sample.</p> 2012-05-09T22:53:28-04:00