gpt4 book ai didi

c# - LINQ 查询未检索保存的数据

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:22 24 4
gpt4 key购买 nike

也许我需要重新开始。感谢 datagridview 的有用链接,但我真的不需要提出来。

问题的本质是:我用这个方法做了两件事:- 添加新记录时从数据库中获取必要的数据- 在更新记录后从数据库中获取必要的数据

public void refreshReservationDetail()
{
_oReservationDetail = (from rd in _oReservation.tblReservationDetails
where rd.ReservationID == _oReservationObject.ID
select rd).ToList();
}

当我添加一条新记录时,新数据被保存并加载到数据 GridView 中。所以这很好用。

当我更新现有记录(已显示在 datagridview 中)时,更改的内容也被正确保存,但上面的方法没有给我保存的数据,但仍然是旧数据。怎么会?

我在这里保存我的数据

//frmReservationDetail
public event dRefresh SavedActivity;

private void btnOk_Click(object sender, EventArgs e)
{
_oReservationDetail.ReservationDetailData.ReservationID = _oReservationDetail.ReservationObjectData.ID;
_oReservationDetail.ReservationDetailData.StartTime = Convert.ToDateTime(_oReservationDetail.ReservationObjectData.StartTime.Value.ToString("dd/MM/yyyy") + " " + _oDateTime[cboStartTime.getSelectedID()]);
_oReservationDetail.ReservationDetailData.EndTime = Convert.ToDateTime(_oReservationDetail.ReservationObjectData.StartTime.Value.ToString("dd/MM/yyyy") + " " + _oDateTime[cboEndTime.getSelectedID()]);
if (this.cboLanguage.SelectedItem != null)
{
_oReservationDetail.ReservationDetailData.LanguageID = this.cboLanguage.getSelectedID();
}
else
_oReservationDetail.ReservationDetailData.LanguageID = null;

if (this.cboTargetgroup.SelectedItem != null)
{
_oReservationDetail.ReservationDetailData.TargetgroupID = this.cboTargetgroup.getSelectedID();
}
else
_oReservationDetail.ReservationDetailData.TargetgroupID = null;

if (this.cboExcursion.SelectedItem != null)
{
_oReservationDetail.ReservationDetailData.ExcursionID = this.cboExcursion.getSelectedID();
}
else
_oReservationDetail.ReservationDetailData.ExcursionID = null;

_oReservationDetail.ReservationDetailData.Participants = int.Parse(this.txtParticipants.Text);
_oReservationDetail.ReservationDetailData.Leaders = int.Parse(this.txtLeaders.Text);
_oReservationDetail.ReservationDetailData.Remarks = this.txtRemarks.Text;
_oReservationDetail.save();

if(SavedActivity != null)
SavedActivity();

this.Close();
}

//clsReservationDetail
public void save()
{
int i = _oReservationDetail.ID;
if (_oReservationDetail.ID == 0)
{
_oReservation.tblReservationDetails.InsertOnSubmit(_oReservationDetail);
_oReservation.SubmitChanges();
}
_oReservation.SubmitChanges();
}

最佳答案

听起来您没有重新绑定(bind)数据 GridView 。保存/更新后,您应该再次调用 refreshReservationDetail(),然后您需要再次将数据源设置为该变量并重新绑定(bind)它。如果您使用更新面板或类似的异步方式执行此操作,则必须在为保存/更新而触发的事件结束时调用 refreshReservationDetail()。如果页面正常回发,那么无论是否回发,只要确保数据绑定(bind)到 gridview 即可。

关于c# - LINQ 查询未检索保存的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8296749/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com