【发布时间】:2009-09-11 19:55:17
【问题描述】:
我想在我的网格中添加一个空行。
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton id="Insert" runat="server" CausesValidation="false"
CommandName="Insert" OnClick="GridViewInsert"
ImageUrl="~/Images/Grid/Insert.gif" />
在 GridViewInsert 事件中:
Award_Status_List list = new Award_Status_List();
list.Award_Status_Code = " ";
list.Award_Status_Desc = " ";
list.Is_Active = false;
list.Job_User = " ";
list.Job_Name = " ";
list.Job_Date = DateTime.Now;
_entity.AddToAward_Status_List(list);
_entity.SaveChanges();
GridView2.DataBind();
在保存更改时出现此错误:
System.Data.OptimisticConcurrencyException 未被用户代码处理 Message="存储更新、插入或删除语句影响了意外数量的行 (0)。自加载实体以来,实体可能已被修改或删除。刷新 ObjectStateManager 条目。" 源="系统.数据.实体" 堆栈跟踪: 在 System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter 适配器) 在 System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache) 在 System.Data.Objects.ObjectContext.SaveChanges(布尔型 acceptChangesDuringSave) 在 System.Data.Objects.ObjectContext.SaveChanges() 在 c:\Documents and Settings\mranganathan\My Documents\Visual Studio 2008\WebSites\Accounting\Default1.aspx.cs:line 68 中的 Default1.GridViewInsert(Object sender, EventArgs e) 在 System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) 在 System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(字符串 eventArgument) 在 System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串 eventArgument) 在 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,字符串 eventArgument) 在 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) 在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
【问题讨论】:
标签: entity-framework stored-procedures gridview entity