Jump to content
Sign in to follow this  
safetyweek

[C#] An error occurred while attempting to update the row

Recommended Posts

Hi there: I can do it update records in the GridView.This is the error:An error occurred while attempting to update the row. Why?Default4.aspx:

<%@ Page Language="C#" %><%@ Import Namespace="System.Data" %><%@ Import Namespace="System.Data.Odbc" %><%@ Import Namespace="System.Configuration" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">public void Page_Load (Object sender, EventArgs e){	OdbcConnection myConnectionString = new OdbcConnection(ConfigurationManager.ConnectionStrings["ConnMySQL"].ConnectionString);	myConnectionString.Open();		myConnectionString.Close();	  }protected void GridView1_RowUpdated(Object sender, GridViewUpdatedEventArgs e){	if (e.Exception != null)	{		Message.Text = "Row updated successfully.";   	}	else	{		e.ExceptionHandled = true;		Message.Text = "An error occurred while attempting to update the row.";		}}protected void GridView1_RowCancelingEdit(Object sender, GridViewCancelEditEventArgs e){	Message.Text = "";}protected void GridView1_RowEditing(Object sender, GridViewEditEventArgs e){	Message.Text = "";}</script><html xmlns="http://www.w3.org/1999/xhtml"><head id="Head1" runat="server">	<title></title></head><body><form id="form1" runat="server"><div><asp:label id="Message" forecolor="Red" runat="server"/><asp:SqlDataSource ID="SqlDataSource1" runat="server"	ConnectionString="<%$ ConnectionStrings:ConnMySQL %>" 	ProviderName="<%$ ConnectionStrings:ConnMySQL.ProviderName %>" 	DataSourceMode="DataSet"	SelectCommand="SELECT * FROM tbl_login" 	UpdateCommand="UPDATE tbl_login SET name=@name, c=@c WHERE ID=@original_ID"><UpdateParameters><asp:Parameter Type="String" Name="name" /><asp:Parameter Type="String" Name="c" /></UpdateParameters></asp:SqlDataSource><asp:GridView ID="GridView1" runat="server" AllowPaging="True" 	AllowSorting="True" PageSize="20" DataSourceID="SqlDataSource1" 	DataKeyNames="ID" AutoGenerateColumns="False" AutoGenerateEditButton="False"	onrowupdated="GridView1_RowUpdated"	onrowcancelingedit="GridView1_RowCancelingEdit"	onrowediting="GridView1_RowEditing">	<PagerStyle HorizontalAlign="Left" />	<Columns>	<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="true" />	<asp:BoundField DataField="Email" HeaderText="Email" HtmlEncode="False" DataFormatString="<a href='mailto:{0}'>{0}</a>" />	<asp:BoundField DataField="name" HeaderText="name" />	<asp:BoundField DataField="c" HeaderText="c" />	<asp:CommandField ShowHeader="true" HeaderText="Edit" ShowEditButton="true" />		<asp:TemplateField>					<ItemTemplate>			</ItemTemplate>						</asp:TemplateField>	</Columns><PagerSettings Position="TopAndBottom" FirstPageText="First page" LastPageText="Last page" Mode="NextPreviousFirstLast" /><PagerSettings /></asp:GridView></div></form></body></html>

Edited by safetyweek

Share this post


Link to post
Share on other sites
Hi there: I can do it update records in the GridView.This is the error:An error occurred while attempting to update the row. Why? else { e.ExceptionHandled = true; Message.Text = "An error occurred while attempting to update the row."; }
Well, while it is very wise to hide all directly generated error messages in released code I don't see why you would want to hide it during development. I believe the object e has an associated message e.message. Print it.

Share this post


Link to post
Share on other sites
Well, while it is very wise to hide all directly generated error messages in released code I don't see why you would want to hide it during development. I believe the object e has an associated message e.message. Print it.
Thanks Sir.I try this:
protected void GridView1_RowUpdated(Object sender, GridViewUpdatedEventArgs e)	{	if (e.Exception != null)	{		Message.Text = "Row updated successfully.";   	}	else	{		e.ExceptionHandled = true;		Message.Text = e.Exception.Message;		}}

But I have this error:

Source=App_Web_rkhwabmm StackTrace: in ASP.default4_aspx.GridView1_RowUpdated(Object sender, GridViewUpdatedEventArgs e) in c:\Inetpub\wwwroot\_aspx\Default4.aspx:line 28 in System.Web.UI.WebControls.GridView.OnRowUpdated(GridViewUpdatedEventArgs e) in System.Web.UI.WebControls.GridView.HandleUpdateCallback(Int32 affectedRows, Exception ex) in System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) in System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) in System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) in System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) in System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) in System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) in System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) in System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) in System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) in System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) in System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) in System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) in System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) InnerException:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...