Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC更新第二个表_C#_Database_Model View Controller - Fatal编程技术网

C# MVC更新第二个表

C# MVC更新第二个表,c#,database,model-view-controller,C#,Database,Model View Controller,当我的编辑页面向“记录”表提交更改时,我试图在另一个表中添加“历史记录”。我想保存记录ID、日期、用户ID和已更改的旧值(列名、更改内容和更改内容)的描述列表 到目前为止,基本控制器是: // GET: Record/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest);

当我的编辑页面向“记录”表提交更改时,我试图在另一个表中添加“历史记录”。我想保存记录ID、日期、用户ID和已更改的旧值(列名、更改内容和更改内容)的描述列表

到目前为止,基本控制器是:

// GET: Record/Edit/5
public ActionResult Edit(int? id)
{
    if (id == null)
    {
        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    }
    TM_Records tM_Records = db.TM_Records.Find(id);
    if (tM_Records == null)
    {
        return HttpNotFound();
    }
    ViewBag.Consult_Type = new SelectList(db.TM_Consult_Types, "TM_Consult_Type_ID", "TM_Consult_Type_Name", tM_Records.Consult_Type);
    ViewBag.Department = new SelectList(db.TM_Departments, "Dept_ID", "Dept_Name", tM_Records.Department);
    ViewBag.FSC = new SelectList(db.TM_FSCs_dim, "TM_FSC_ID", "TM_FSC_NAME", tM_Records.FSC);
    ViewBag.Gender = new SelectList(db.TM_Genders_dim, "TM_Gender_ID", "TM_Gender_Name", tM_Records.Gender);
    return View(tM_Records);
}

// POST: Record/Edit/5
// To protect from overposting attacks, please enable the specific properties you want to bind to, for 
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit([Bind(Include = "Index_key,Hospital,NMXS_Consult_ID,DateTime_Requested,DateTime_Answered,DateTime_Completed,Patient_Name,DOB,MRN,Requesting_Provider,Consulting_Provider,Duration_Minutes,Ready_to_Review,DateTime_Reviewed,Bill_To,Bill_Amount,Consulting_Provider_ID,Requester_NPI,DateTime_Billed,DateTime_Payment_received,Amt_Received,Reconcile_Exception_Amt,File_Location,Initial_Diagnosis,Final_Diagnosis,Date_Loaded,Date_Updated,Gender,FSC,Consult_Type,Rec_Notes,Department,Valid_Record,DateTime_Billed_Rpt_Run")] TM_Records tM_Records)
{
    if (ModelState.IsValid)
    {
        db.Entry(tM_Records).State = EntityState.Modified;
        db.SaveChanges();
        return RedirectToAction("Index");
    }
    ViewBag.Consult_Type = new SelectList(db.TM_Consult_Types, "TM_Consult_Type_ID", "TM_Consult_Type_Name", tM_Records.Consult_Type);
    ViewBag.Department = new SelectList(db.TM_Departments, "Dept_ID", "Dept_Name", tM_Records.Department);
    ViewBag.FSC = new SelectList(db.TM_FSCs_dim, "TM_FSC_ID", "TM_FSC_NAME", tM_Records.FSC);
    ViewBag.Gender = new SelectList(db.TM_Genders_dim, "TM_Gender_ID", "TM_Gender_Name", tM_Records.Gender);
    return View(tM_Records);
}
我正在尝试向TM_历史记录表添加一条新记录,其中包含以下详细信息:

Columns:
TM_Hist_ID, (primary key)
TM_Hist_Record_ID, (the record that was modified)
TM_Hist_Date, (populate with now())
TM_Hist_Values, (changes e.g. Price: $320 >> $220 | Note: "" >> $100 coupon)
TM_Hist_Ident_ID (User.Identity.Name)
我搜索了stackoverflow,没有找到任何适用于此问题的答案

谢谢你的考虑


罗伯特

我甚至不知道你的问题是什么。您的问题是什么?在处理记录更改的过程中,如何使用此信息向TM_历史记录表中添加新记录?您是否调查过SQL Server中的更改跟踪?可能不需要自己动手。Dave R:不与SQL server交互的最终用户需要能够查看信息,SQL server中的更改跟踪是否满足这一要求?显然,SQL server的更改跟踪有一些限制,我的数据库管理员说不允许我们将其用于此特定应用程序。不过知道这件事很酷。