On a form, is it possible to call an Adapter with multiple keys? I’m working in a form customization and trying to call the ShipTo table to pull the specific ShipTo information (Name/Addr/City/etc) to display on screen. Essentially, on the form the user selects the customer and shipto id, then I need to take that to pull the other fields.
I declared vars for the key fields: Company, ShipToCustNum, and ShipToNum but the method never connects. I have a testing message box in the try that never fires so it’s failing.
Here is the method I have, I first pull the needed data from the OrderHed table in another method and set it to Vars: SOCustID, SOCompany, and SOShipTo referenced below.
private void GetShipToInfo() // Get ShipTo info
{
try
{
MessageBox.Show("Get ShipTo info method start"); //TEST
// Declare and Initialize EpiDataView Variables
EpiDataView edvRMAHead = ((EpiDataView)(this.oTrans.EpiDataViews["RMAHead"]));
// Check if valid EpiDataView Row(s) are selected
if ((edvRMAHead.Row < 0))
{
return;
}
// Declare and create an instance of the Adapter
ShipToAdapter adapterShipTo = new ShipToAdapter(this.oTrans);
adapterShipTo.BOConnect();
// Declare and Initialize Variables
int RMACust = SOCustID; // CustNum to link RMAHead to ShipTo
string RMACompany = SOCompany; //CustNum to link RMAHead to ShipTo
string RMAShipToNum = SOShipTo; // CustNum to link RMAHead to ShipTo
// Call Adapter method
System.Data.DataSet dsShipToNum = adapterShipTo.GetByID(RMACompany, RMACustID, RMAShipToNum);
DataRowCollection dsShipTo = dsShipToNum.Tables["ShipTo"].Rows;
foreach (DataRow STrow in dsShipTo)
{
EpiDataView RMAHead = (EpiDataView)oTrans.EpiDataViews["RMAHead"];
RMAHead.dataView[RMAHead.Row].BeginEdit();
RMAHead.dataView[RMAHead.Row]["PkUpName_c"] = STrow["Name"].ToString();
RMAHead.dataView[RMAHead.Row].EndEdit();
//TEST
MessageBox.Show("ShipTo info " );
//TESTING
}
// Cleanup Adapter Reference
adapterShipTo.Dispose();
}
catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}
}
As a test, can you remove the try/Catch block and hard code in some values for the variables?
With a try/catch and your return out if the row is less than 0, i’ve seen it before execute the return prior to rendering the msg box. I want to see where it’s failing and the try/catch will hide this
Same situation, the first message box at the top of the method fired but not the one in the ForEach loop, so it’s not connecting to the ShipTo table correctly.
Object Explorer will show you all the methods and properties of an adapter, although sometimes using the Business Logic Testers is a little easier to visualize.
I’m trying to get the ShipTo information; Name, Address, City, State, Zip to put it into UD fields on the RMAHead table. For example: ShipTo.Name to RMAHead.STName_c
ShipToAdapter adapterShipTo = new ShipToAdapter(oTrans);
adapterShipTo.BOConnect();
bool result = adapterShipTo.GetByID(SOCustID, SOShipTo); //Erp.Tablesets.ShipToTableset GetByID(int custNum, string shipToNum)
if(result)
{
foreach(var row in adapterShipTo.ShipToData.ShipTo.Rows)
{
To here everything is golden, then I tried to pull data from ShipTo. For example when I tried, string STName = row[“Name”].ToString(); a test compile gives the error: “Cannot apply indexing with [] to an expression of type ‘object’” I’ve seen this before and had to make a EpiDataView. Which is the code giving you hives.
@duckor and @Aaron_Moreng are amazing! I owe you both a drink if we ever meet. Once again you guys have rescued this know-just-enough-to-get-into-trouble self. Wish I could give you both a “solution” check.
You too @Hally
I tried something similar but didn’t have the [0] bracket and it was giving me indexing error inside the foreach. I’ll be sure to update my stash of code snips I use to self-help and a few other resources I try to not overuse you guys here.
parsing the code: adapterShipTo.ShipToData.ShipTo[0].Name.ToString();
adapterShipTo I understand as it’s been declared in the code when accessing the adapter
.ShipToData.ShipTo[0] This one must specify the data to access but what is the [0] for?
.Name.ToString() is the fieldname and converting it to string.
the indexer “[]” is telling the code which row of the data to access. In this case, because we performed a GetByID on a specific ShipTo record, we should have 1 row of information in that index. In C#, indexes start at 0, so it says to look at position 0 of the index to identify the record you’re interested in.