Reputation: 483
maybe I need to start over. Thx for the helpful links for the datagridview but I didn't really need to bring that up.
The essence of the problem is this: I use this method for 2 things: - to get the necessary data out of the database when adding a new record - to get the necessary data out of the database after I've updated a record
public void refreshReservationDetail()
{
_oReservationDetail = (from rd in _oReservation.tblReservationDetails
where rd.ReservationID == _oReservationObject.ID
select rd).ToList();
}
When I add a new record the new data is saved and loaded into the datagridview. So this works fine.
When I update an existing record (that is already shown in the datagridview) the altered content is also being saved properly but the method above is not giving me the saved data but still the old data. How come?
Here I save my data
//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();
}
Upvotes: 2
Views: 338
Reputation: 483
I have succeeded by calling this loop:
foreach (var oReservationDetail in
_oReservationObject.ReservationData.tblReservationDetails)
I have used the setted relations in the database instead of querying again to get the data. It now works!
Upvotes: 0
Reputation: 10478
It sounds like you aren't rebinding your datagridview. After you save/update you should be calling refreshReservationDetail()
again, and then you'll need to once again set the datasource to that variable and rebind it. If you are doing this asynchronously with an update panel or some such, you'll have to call refreshReservationDetail()
at the end of the event that is fired for saving/updating. If the page is posting back normally then just make sure your databinding to the gridview occurs regardless if it's a postback or not.
Upvotes: 1