Update Sales Order

Alright this is what I have so far…

	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			// Declare and create an instance of the Adapter.
			SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(this.oTrans);
			adapterSalesOrder.BOConnect();
			
			var orderHead = oTrans.Factory("OrderHead"); //is this spelled right?
			int orderNum = (int)orderHead.dataView[orderHead.Row]["OrderNum"];
		(Line 1640)	var currentOrder = adapterSalesOrder.SalesOrderData.OrderHed.AsEnumerable().Where(w => (int)w["OrderNum"] == orderNum).FirstOrDefault(); 
				if(currentOrder != null)
			{
				currentOrder["OrderHed_OTSName"] = tbOrderNameUpdateShip.Text;
			}
			
			// Call Adapter method
			bool result = adapterSalesOrder.Update();
			// Cleanup Adapter Reference
			adapterSalesOrder.Dispose();

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


Error: CS1061 - line 1641 (9349) - 'System.Data.EnumerableRowCollection<System.Data.DataRow>' does not contain a definition for 'FirstOrDefault' and no extension method 'FirstOrDefault' accepting a first argument of type 'System.Data.EnumerableRowCollection<System.Data.DataRow>' could be found (are you missing a using directive or an assembly reference?)

Change that to;
currentOrder[“OTSName”] = tbOrderNameUpdateShip.Text;

Also, looks like the OrderHead edv is actually named OrderHed, you’ll want to change that too

Still getting this error:
Error: CS1061 - line 1640 (9348) - ‘System.Data.EnumerableRowCollection<System.Data.DataRow>’ does not contain a definition for ‘FirstOrDefault’ and no extension method ‘FirstOrDefault’ accepting a first argument of type ‘System.Data.EnumerableRowCollection<System.Data.DataRow>’ could be found (are you missing a using directive or an assembly reference?)

	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			// Declare and create an instance of the Adapter.
			SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(this.oTrans);
			adapterSalesOrder.BOConnect();
			
			var orderHead = oTrans.Factory("OrderHed"); //is this spelled right?
			int orderNum = (int)orderHead.dataView[orderHead.Row]["OrderNum"];
			(Line 1640) var currentOrder = adapterSalesOrder.SalesOrderData.OrderHed.AsEnumerable().Where(w => (int)w["OrderNum"] == orderNum).FirstOrDefault(); 
				if(currentOrder != null)
			{
				currentOrder["OTSName"] = tbOrderNameUpdateShip.Text;
			}
			
			// Call Adapter method
			bool result = adapterSalesOrder.Update();
			// Cleanup Adapter Reference
			adapterSalesOrder.Dispose();

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

try adding using System.Linq; at top

Okay, ,it compiled but it didn’t actually update anything.

Wait, hold on a second.

I get this error.

You are creating a new adapter you need to get a hold of the current adapter instead.

You connected your BO, but you never got a new or existing dataset. You’ll have to do that somewhere in your code.

Try this instead of making a new adapter

SalesOrderAdapter adapterSalesOrder= (SalesOrderAdapter)csm.TransAdaptersHT["oTrans_adapter"];
//Rest of your code
1 Like

Good catch, I didnt even notice that. That’s why I mentioned earlier, you should already have the data loaded.

Okay, I changed that. Now I’m getting this error:

I put in some message boxes to help. I got to the “2nd Step Sales Order Update” and then this error came up.

	{
		try
		{
			// Declare and Initialize EpiDataView Variables
			// Declare and create an instance of the Adapter.
			MessageBox.Show("Start Sales Order Update");
			SalesOrderAdapter adapterSalesOrder = (SalesOrderAdapter)csm.TransAdaptersHT["oTrans_adapter"];
			MessageBox.Show("2nd Step Sales Order Update");
			adapterSalesOrder.BOConnect();
			
			MessageBox.Show("3rd Step Sales Order Update");
			var orderHead = oTrans.Factory("OrderHed"); //is this spelled right?
			MessageBox.Show("4th Step Sales Order Update");
			int orderNum = (int)orderHead.dataView[orderHead.Row]["OrderNum"];
			MessageBox.Show("SAles Order Update");
			var currentOrder = adapterSalesOrder.SalesOrderData.OrderHed.AsEnumerable().Where(w => (int)w["OrderNum"] == orderNum).FirstOrDefault(); 
				if(currentOrder != null)
			{
				MessageBox.Show("SalesOrderUpdate2");
				currentOrder["OTSName"] = tbOrderNameUpdateShip.Text.ToString();
			}
			MessageBox.Show("SalesOrderUpdate3");
			
			// Call Adapter method
			bool result = adapterSalesOrder.Update();
			// Cleanup Adapter Reference
			adapterSalesOrder.Dispose();

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

ok no BO Connect needed you are getting a hold of the current adapter… I’m assuming there’s one there already? But frankly this thread is too long to follow… Is this happening inside Order Entry?

It’s making my head hurt…
This is inside of a Dashboard.

OH!!! I take it back… put it back the way you had it then you need to do a GetByID
However I see you are doing a oTrans.Factory(“OrdereHed”) I doubt you have a dataview called OrderHed in the current dashboard…
This thread is just too long for me to go back and figure this out… What is the name of your DataView which contains the OrderNum?

I take back my delete!!

Okay so I have a Dashboard in which I have a BAQ Data View called edvGS_Order_Detail_DataView;. I find a record in that DataView by Order Num. Once it is displayed in my dashboard I want to be able to change the OTSName in the actual Sales Order Record. I would like to be able to have Customer Service just enter text into a text box and click update and it will change in the Sales Order Record.

ok so get a hold of your orderNumber… something like this should work. Mind you I’m going from memory so spelling may be crap…

var orderNum = yourDataView.dataView[yourDataView.Row]["OrderDtl_OrderNum"] as int;
//Then do this
SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(this.oTrans)
adapterSalesOrder.BOConnect();

adapterSalesOrder.GetByID(orderNum);
adapterSalesOrder.SalesOrderData.OrderHed[0].OTSName ="Your thing";
adapterSalesOrder.SalesOrderData.OrderHed[0].RowMod="U";
adapterSalesOrder.Update();
adapterSalesOrder.Dispose();

image

1 Like

Okay this is what I’ve got:

	private void CallSalesOrderAdapterUpdateMethod()
	{
		try
		{
	(Line 1684)		var orderNum = edvGS_Order_Detail_DataView.dataView[edvGS_Order_Detail_DataView.Row]["OrderHed_OrderNum"] as int;
			SalesOrderAdapter adapterSalesOrder = new SalesOrderAdapter(this.oTrans);
			adapterSalesOrder.BOConnect();
			//adapterSalesOrder.SalesOrderAdapter.OrderHed.OTSName = tbOrderNameUpdateShip.Text;
			adapterSalesOrder.GetByID(orderNum);
			adapterSalesOrder.SalesOrderData.OrderHed[0].OTSName = "Shannon";
			adapterSalesOrder.SalesOrderData.OrderHed[0].RowMod="U";
			adapterSalesOrder.Update();
			adapterSalesOrder.Dispose();

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

Error: Error: CS0077 - line 1684 (9440) - The as operator must be used with a reference type or nullable type (‘int’ is a non-nullable value type)