Update Contact Info

I am using the Wizard to update the Customer Contact Info.
I keep getting the following error:

How do you figure out what the ID key is?

My code:

	private void CallCustCntAdapterUpdateMethod()
	{
		try
		{
			var intID = Convert.ToInt32(tbContactPerConID.Text);
			CustCntAdapter adapterCustCnt = new CustCntAdapter(this.oTrans);
			adapterCustCnt.BOConnect();
			MessageBox.Show("Before Get By ID");
			adapterCustCnt.GetByID(intID);
			MessageBox.Show("After Get By ID");	
			adapterCustCnt.CustCntData.CustCnt[0].Name = tbContactName.Text;
			MessageBox.Show("After Name Contact");
			bool result = adapterCustCnt.Update();

			adapterCustCnt.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}

Usually the best way is to use the Object Explorer.

For CustCnt it’s CustNum, ShipToNum, ConNum from memory - but the Object Explorer will tell you.

Okay, I looked in Object Explorer - I don’t find anything about GetByID.

How would I put that in my code anyway? How do you know what order it is looking for it in?

From what you’ve put, I’m assuming you’re using the CustCnt adapter from a customisation for a screen that doesn’t natively use it.

If you look at the “Adapters” tab of Object Explorer, and go to the CustCntAdapter, you’ll find all its methods listed, the same in every form, including GetByID. If you select that method, it will show you the signature (the arguments you need to pass in and what it returns). The examples are VB, which isn’t very helpful, but the pattern is always relevant regardless.

Yup, I did all that and got this:

I tried to use that code and I got errors. :frowning:

	private void CallCustCntAdapterGetPerConDataMethod()
	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			// Declare and create an instance of the Adapter.
			CustCntAdapter adapterCustCnt = new CustCntAdapter(this.oTrans);
			adapterCustCnt.BOConnect();

			// Declare and Initialize Variables
			// TODO: You may need to replace the default initialization with valid values as required for the BL method call.
			int PerConID = 1170;

			// Call Adapter method
			bool result = adapterCustCnt.GetPerConData(PerConID);
			MessageBox.Show("After Get By ID");	
			adapterCustCnt.CustCntData.CustCnt[0].Name = tbContactName.Text;
			MessageBox.Show("After Name Contact");
			adapterCustCnt.Update();
			adapterCustCnt.Dispose();

		} catch (System.Exception ex)
		{
			ExceptionBox.Show(ex);
		}
	}

image

I don’t think GetPerConData returns a CustCnt. It isn’t necessarily a one-to-one relationship between the two.

It doesn’t work without the “0” in 01 which seems odd, but makes sense since it’s a string. Also, the CustNum is not the same as CustID. The CustID is what it presented to the user, but the CustNum is what the system uses in the back end. I’m not 100% sure if it’s in the dataview, but I would bet it is. It seems odd that you would have to convert the the way that you are doing, so I’m wondering if you have the wrong piece of data for the ID.

So your GetById needs to look like,

adapterCustCnt.GetByID(intID, "ship to string here", ContactNumberIntHere)

(you really should get the BL tester set up so you can test your calls. It will help you out quite a bit.)