We are getting errors about data is being updated by another. I have narrowed it down to the following code snipet. Is there a OTrans.refresh I should add? This is legacy code that I am working with, so pick away. lol
Those errors are annoying. I don’t have an answer for you but this code looks a bit redundant. edvUD03 and updateView are the same beast. No need to make the second reference. Same for the row.
I’ve heard rumor that BeginEdit and EndEdit are unneeded in this case. Try that.
Ken
Don’t instanciate your own adapter.
The issue here is that you have the record on the screen under your current session / adapter then in your code you are instanciating a new UD03 to change the data. This leaves the data on the screen in am “old” state so that when you try to modify the epidataview it sees a difference between the record you changed with your new adapter and the record currently loaded on the screen.
Instead of doing ud03update adapter = new UD03Adapter()… You should get a hold of the current adapter that you are already working with.
You do that by pulling it from oTrans by name
Like this
Mycurrentadapter = (UD03Adapter)csm.TransAdapterHT[“oTrans_Adapter”];
Mind you I’m typing on my phone but you get the gist
Ok so that code gets a hold of the current UD03 adapter. See where it says (EpiBaseAdapter). You can replace that with UD03Adapter and then use oTrans_adapter everywhere else in your code as the UD03 adapter.
IN your other code, the Commented lines need to go and need to be replaced with the above oTrans_Adapter.
private void UpdateNotificationDates(string type)
{
try
{
EpiDataView edvUD03 = ((EpiDataView)(oTrans.EpiDataViews["UD03"]));
System.Data.DataRow edvUD03Row = edvUD03.CurrentDataRow;
if (edvUD03Row != null)
{
EpiDataView updateView = (EpiDataView)oTrans.EpiDataViews["UD03"];
DataRow updateRow = updateView.CurrentDataRow;
//Don't make a new Adapter Here... Causes Issues
/*
UD03Adapter ud03update = new UD03Adapter(oTrans);
ud03update.BOConnect(); */
updateRow.BeginEdit();
if (type == "Tasks") updateRow["Date06"] = DateTime.Now;
else if (type == "Approval") updateRow["Date07"] = DateTime.Now;
else if (type == "Implementation") updateRow["Date08"] = DateTime.Now;
updateRow.EndEdit();
//Use oTrans_Adapter instead
oTrans_Adapter.Update();
}
else MessageBox.Show("Warning - edvUD03Row is NULL");
}
catch (Exception ex) { MessageBox.Show("Exception thrown by UpdateNotificationDates: " + ex.Message); }
}
Yup, I’m not sure how that ever worked reliably… you should have gotten that Record Modified by XYZ all the time. One thing to remember DO NOT dispose of oTrans_Adapter … unless you want lots and lots of pain.
Remember you are getting a hold of the Current form’s adapter, so if you dispose of it… you dispose of the one in the form… and nothing will work
Yes folks have been saying the form gives errors all the time, but they have been using it for three years like this. I am starting to make changes, but there are many moving parts. When enhancing old code, I try not to recreate outside the scope of the request due to coding style This might be an exception.