Having some issues here. I feel like everything is correct, but it just wont work. I am trying to update a field in table UD01. It runs through the code like it works, but the table doesn’t update. The value for result is “false”. I have checked to verify it is pointing to the correct record to update, and it is. here is my code, what am I missing?
private void epiButtonC1_Click(object sender, System.EventArgs args)
{
if (this.cr.Text == "" || this.cr.Text == null)
{
MessageBox.Show("Please enter a CR#.");
return;
}
try
{
UD01Adapter adapterUD01 = new UD01Adapter(this.oTrans);
adapterUD01.BOConnect();
string whereClause = "Key1 = " + this.cr.Text;
SearchOptions opts = new SearchOptions(SearchMode.AutoSearch);
opts.NamedSearch.WhereClauses.Add("UD01",whereClause);
bool morePages = false;
UD01DataSet UD01ds = (UD01DataSet)adapterUD01.GetRows(opts,out morePages);
DataRow dr = UD01ds.UD01.Rows[0];
dr.BeginEdit();
dr["Character04"] = "TEST";
dr.EndEdit();
oTrans.Update();
bool result = adapterUD01.Update();
MessageBox.Show(Convert.ToString(result));
adapterUD01.Dispose();
MessageBox.Show("CR# " + this.cr.Text + " has been completed.");
this.cr.Text = "";
} catch (System.Exception ex)
{
MessageBox.Show("This CR# does not exist, please enter a valid CR#.");
}
}
Here is a function we use for UD03
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;
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();
ud03update.Update();
}
else MessageBox.Show("Warning - edvUD03Row is NULL");
}
catch (Exception ex) { MessageBox.Show("Exception thrown by UpdateNotificationDates: " + ex.Message); }
}
I think I tried your code, and I still cant get it to work for me. How are you selecting the record to update? Mine needs to be a record where key1 = a text box on my form.
knash, Thank you so much! I knew it would be something stupid. I thought I was pointing the adapter to the correct record, but I was not. This is my final code that I got to work. Essentially I am finding the records that meet the conditions, then using that data for the GetByID, then updating the record. Thannnnnnk you!
UD01Adapter adapterUD01 = new UD01Adapter(this.oTrans);
adapterUD01.BOConnect();