编辑数据错误:更新条目时发生错误。有关详细信息,请参见内部异常。

时间:2019-03-10 10:30:15

标签: c# html asp.net

我通过(callbackPanel_Callback)控件从数据库检索我的数据。 但是当我想编辑一些数据并使用(context.SaveChanges();)更新数据库表时,出现此错误:更新条目时发生错误。有关详细信息,请参见内部异常

这是“编辑按钮”的代码:

     protected void EditBtn_Click(object sender, EventArgs e)
    {

        int ActivityID = int.Parse(Session["ActivityID"].ToString());
        EventInfo = AllEvent.GetActivityByID(ActivityID);

        if (EventInfo != null)
        {

            EventInfo.Title = EditTitile.Text;
            EventInfo.Summary = EditSummary.Text;
            EventInfo.Location = EditActLocation.Text;
            if (EditActDate.Date != null) { EventInfo.ActivityDate = Convert.ToDateTime(EditActDate.Date); }
            if (EditActTime.DateTime != null) { EventInfo.ActivityTime = Convert.ToDateTime(EditActTime.DateTime); }
            EventInfo.ActivityOwnerName = EditActOnwerName.Text;
            if (ASPxHtmlEditor1.Html != null) { EventInfo.Details = ASPxHtmlEditor1.Html; }
            if (EditStartPublishDate.Date != null) { EventInfo.StartPublishDate = Convert.ToDateTime(EditStartPublishDate.Date); }
            if (EditEndPublishDate.Date != null) { EventInfo.EndPublishDate = Convert.ToDateTime(EditEndPublishDate.Date); }


            AllEvent.UpdateActivity(EventInfo);
        }

        ASPxGridView1.DataSource = AllEvent.GetAllActivityEvent();
        ASPxGridView1.DataBind();
    }

这是更新功能:

public bool UpdateActivity(ActivityEvent _ActivityEvent)
    {
        try
        {
            using (MsdRabetEntities context = new MsdRabetEntities())
            {

                ActivityEvent Activity = context.ActivityEvents.SingleOrDefault(s => s.ID == _ActivityEvent.ID);

                Activity.ActivityDate = _ActivityEvent.ActivityDate;
                Activity.Title = _ActivityEvent.Title;
                Activity.ActivityOwnerName = _ActivityEvent.ActivityOwnerName;
                Activity.ActivityTime = _ActivityEvent.ActivityTime;
                Activity.Attachment = _ActivityEvent.Attachment;
                Activity.Details = _ActivityEvent.Details;
                Activity.EndPublishDate = _ActivityEvent.EndPublishDate;
                Activity.StartPublishDate = _ActivityEvent.StartPublishDate;
                Activity.Location = _ActivityEvent.Location;
                //Activity.Priority = _ActivityEvent.Priority;
                Activity.Summary = _ActivityEvent.Summary;


                int success = context.SaveChanges();

                if (success != 0)
                {
                    return true;
                }
                else
                    return false;
            }

这是callbackPanel

        protected void callbackPanel_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e)
    {
        if (IsPostBack)
        {
            int ActivityID = int.Parse(e.Parameter.ToString());
            var ActivityInfo = AllEvent.GetActivityByID(ActivityID);
            EditPopupControl1.ShowOnPageLoad = true;


            if (ActivityInfo != null)
            {
                EditTitile.Text = ActivityInfo.Title;
                EditSummary.Text = ActivityInfo.Summary;
                EditActLocation.Text = ActivityInfo.Location;
                if (ActivityInfo.ActivityDate != null)
                {
                    EditActDate.Date = ActivityInfo.ActivityDate.Value;
                }
                if (ActivityInfo.ActivityTime != null)
                {
                    EditActTime.Value = ActivityInfo.ActivityTime.Value;
                }
                EditActOnwerName.Text = ActivityInfo.ActivityOwnerName;
                if (ActivityInfo.StartPublishDate != null)
                {
                    EditStartPublishDate.Date = ActivityInfo.StartPublishDate.Value;
                }
                if (ActivityInfo.EndPublishDate != null)
                {
                    EditEndPublishDate.Date = ActivityInfo.EndPublishDate.Value;
                }
                ASPxHtmlEditor2.Html = ActivityInfo.Details;
                string StrBase64 = Convert.ToBase64String(ActivityInfo.Attachment);
                ASPxBinaryImage1.ImageUrl = "data:Image/JPEG;base64," + StrBase64;

            }

            Session["ActivityID"] = ActivityID.ToString();
        }
    }

0 个答案:

没有答案