Updating UD01 TableRecord in C#

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#.");
		}
	}

opps didn’t read your whole statement.

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); }
    }

try adding
dr[“RowMod”] = “U”;

before end edit

Didn’t change anything, not sure why I can’t get this to work.

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.

Did you try adding what Bernie suggested? I am guessing the EpiDataView (edv_UD03) I am calling has the rowmod set to “U”

yup, I did, here is my attempt #2:

	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];

		EpiDataView edvPA = new EpiDataView(); 
		edvPA.dataView = new DataView(UD01ds.UD01);
		DataRow dr = edvPA.CurrentDataRow;

		dr.BeginEdit();
		dr["RowMod"] = "U";
		dr["Character04"] = "TEST";
		dr.EndEdit();

		adapterUD01.Update();

		adapterUD01.Dispose();

	MessageBox.Show("CR# " + this.cr.Text + " has been completed.");

	this.cr.Text = "";

	} catch (System.Exception ex)
	{
		MessageBox.Show(Convert.ToString(ex));
		//MessageBox.Show("This CR# does not exist, please enter a valid CR#.");
	}

Are you trying to create a new record or retrieve one in the database?

I think this is close, but there is a mix of Adapter and WCFServiceSupport syntax.

Here is the WFC Service call.

private void CancelECR()
{
try
{
string key1 = currentECR[“Key1”].ToString();
string key2 = currentECR[“Key2”].ToString();
string key3 = currentECR[“Key3”].ToString();
string key4 = currentECR[“Key4”].ToString();
string key5 = currentECR[“Key5”].ToString();

            UD03Impl ud03BO = WCFServiceSupport.CreateImpl<UD03Impl>(FormFunctions.getILaunchSession(oTrans), UD03Impl.UriPath);
            UD03DataSet tempSet = ud03BO.GetByID(key1, key2, key3, key4, key5);

            tempSet.Tables[0].Rows[0]["ShortChar01"] = "Canceled";
            tempSet.Tables[0].Rows[0]["ShortChar02"] = "Canceled";
            tempSet.Tables[0].Rows[0]["ShortChar16"] = currentUser["Name"];
            tempSet.Tables[0].Rows[0]["ShortChar18"] = "Canceled";
            tempSet.Tables[0].Rows[0]["Date10"] = DateTime.Now;

            ud03BO.Update(tempSet);

}}

2 Likes

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();

		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];
		string key1 = Convert.ToString(dr["Key1"]);
		string key2 = Convert.ToString(dr["Key2"]);
		string key3 = Convert.ToString(dr["Key3"]);
		string key4 = Convert.ToString(dr["Key4"]);
		string key5 = Convert.ToString(dr["Key5"]);

		adapterUD01.GetByID(key1, key2, key3, key4, key5);

		DataRow drt = adapterUD01.UD01Data.UD01[0];
		
		drt.BeginEdit();
		drt["CheckBox01"] = "True";
		drt["RowMod"] = "U";
		drt.EndEdit();

		adapterUD01.Update();

		adapterUD01.Dispose();