我有一個保存按鈕,它將在我的'IncidentActions'表中添加新數據,並同時更新'Incident'表中的3列。如何在一個表中插入數據並使用linq更新sql數據庫中的另一個表
我怎麼會去這樣做
這裏是我使用的嘗試做到這點的C#代碼。
protected void cmdSave_Click(object sender, EventArgs e)
{
Context db = new Context();
// This will check the Action from the actions table and
var actionID = (from i in db.Actions
where i.Actions == tbActionType.Text
select i.ActionsID).First();
long ID = Convert.ToInt64(Request.QueryString["IncidentID"]);
// TODO: update the incident table accordingly
IncidentAction act = new IncidentAction
{
IncidentID = ID,
ActionDate = (DateTime)dpActionDate.SelectedDate,
ActionsID = Convert.ToInt32(actionID),
StatusID = statID,
IsPublic = false,
Title = tbTitle.Text.Trim(),
PeriodValue = Convert.ToInt64(txtDuration.Text),
Description = txtDescription.Text.Trim(),
EstimatedCost = txtEstimatedCost.Text == string.Empty ? (decimal?)null : Convert.ToDecimal(txtEstimatedCost.Text),
ActualCost = txtActualCost.Text == string.Empty ? (decimal?)null : Convert.ToDecimal(txtActualCost.Text),
LastUpdated = DateTime.Now,
UpdatedBy = Convert.ToString(loggedInUserName),
CreatedByUserID = Convert.ToInt32(loggedInUserID),
Active = true
};
db.IncidentActions.Add(act);
db.SaveChanges();
Incident inc = new Incident
{
IncidentID = ID,
StatusID = statID_new,
IncidentPendingDate = DateTime.Now
};
db.SaveChanges();
}
}
這個代碼
的結果是什麼問題此時此刻? – SamiHuutoniemi
啊其所有好帥哥, 我得到它排序:D 虐待我的答案tomoro一旦我能夠回答我自己的問題 – user2343291