Error with BAQ query code

I am trying to populate a text box with the Value from a Query of a BAQ. I want to fill in the below box with a calculated field of stdcost from the part cost table. I have watched a couple things to get to the point I am at now, but I am getting the the error below the code. I think that this is the easiest way to populate that field but i am having issues.

image

            EpiDataView edvPODetail = ((EpiDataView)(this.oTrans.EpiDataViews["PODetail"]));		 
            string partnum = Convert.ToString(edvPODetail.dataView[edvPODetail.Row]["partnum"]);
	DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
            dqa.BOConnect();
            QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("PartCostStdCost");
            qeds.ExecutionParameter.Clear();
	qeds.ExecutionParameter.AddExecutionParameterRow("PartParam", partnum,  "nvarchar",false, Guid.NewGuid(),"A");
	dqa.ExecuteByID("PartCostStdCost", qeds);
            PartCost = dqa.QueryResults.Tables["Results"];

Error: CS0029 - line 96 (550) - Cannot implicitly convert type ‘System.Data.DataTable’ to ‘Ice.Lib.Framework.EpiNumericEditor’

What is the variable PartCost?

My guess is you need to extract the PartCost from the BAQ , then set the field to the extracted part costs.

This may help point you in the right direction if your BAQ is only returning 1 row.
PartCost = dqa.QueryResults.Tables[0].Rows[0][“ColumnName”]

PartCost is the name of the field that I am trying to populate.

I assume your EpiNumericEditor is named “PartCost”. This will need to have its “Value” property set.
Also, you are trying to put the entire table from the query in the EpiNumericEditor. You have to select a single row (even if there is only one) and a single column (even if there is only one).

EpiDataView edvPODetail = ((EpiDataView)(this.oTrans.EpiDataViews["PODetail"]));		 
string partnum = Convert.ToString(edvPODetail.dataView[edvPODetail.Row]["partnum"]);
DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
dqa.BOConnect();
QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("PartCostStdCost");
qeds.ExecutionParameter.Clear();
qeds.ExecutionParameter.AddExecutionParameterRow("PartParam", partnum,  "nvarchar",false, Guid.NewGuid(),"A");
dqa.ExecuteByID("PartCostStdCost", qeds);
PartCost.Value = dqa.QueryResults.Tables["Results"].Rows[0]["Calculated_StdCost"];
1 Like

That was it, Thank you!

@Jason_Woods What is this part of the code doing?

Guid.NewGuid(),“A”);

These are simply required parameters to the method. I would have to look it up to see what the “A” means, but the GUID is simply a placeholder.

I m having an issue with the code I have so far. Now I am trying to make a variable and compare it to the BAQ query value I have. It works for the first go through, If the value is greater then show message, but then they change the vlaue to make it false, and the message box shows still, i think it is because it is getting the stored field from the DB, so I might be getting the value for UnitCost in the wrong location. Maybe I got to deep into the rabbit hole. Code is below.

private void PODetail_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{

    // ** Argument Properties and Uses **
    // args.Row["FieldName"]
    // args.Column, args.ProposedValue, args.Row
    // Add Event Handler Code

    EpiDataView edvPODtl = ((EpiDataView)(this.oTrans.EpiDataViews["PODetail"]));
    UnitCost = Convert.ToDouble(edvPODtl.dataView[edvPODtl.Row]["ScrUnitCost"]);
    if (!(String.IsNullOrEmpty(Convert.ToString(args.Row["PartNum"]))))
    {
        EpiDataView edvPODetail = ((EpiDataView)(this.oTrans.EpiDataViews["PODetail"]));
        var partnum = Convert.ToString(edvPODetail.dataView[edvPODetail.Row]["partnum"]);

        DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
        dqa.BOConnect();
        QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("PartCostStdCost");
        qeds.ExecutionParameter.Clear();

        qeds.ExecutionParameter.AddExecutionParameterRow("PartParam", partnum, "nvarchar", false, Guid.NewGuid(), "A");
        dqa.ExecuteByID("PartCostStdCost", qeds);


        PartCost.Value = dqa.QueryResults.Tables["Results"].Rows[0]["Calculated_totalCost"];
    }
    if (!(String.IsNullOrEmpty(Convert.ToString(args.Row["ScrUnitCost"]))))
    {
        UnitCost = Convert.ToDouble(edvPODtl.dataView[edvPODtl.Row]["ScrUnitCost"]);    

        if (UnitCost > Convert.ToDouble(PartCost.Value))
        {
            MessageBox.Show("WARNING: The Unit Cost is more then the Standard Cost");
        }
    }
}

Which value are you changing to make this false?

UnitCost is set to ScrUnitCost which is a database field, It takes that change and I am guessing writes to the Database. if that value is greater then the PartCost.Value, I want it to show a message, which it does with the nested if statement. The issue is that if I go in and change that ScrUnitCost < PartCost, then the unit cost goes out to the Database and gets unitscost = scrunitcost from the database, but it is still the old value which is greater then StdCost so the message shows even though the new price is lower. That is the best I can explain the error, I am probably taking the long way around or doing it the hard way.

So you are changing both the purchase cost and the standard cost for this screen?

No the standard cost i am pulling in from the query of the BAQ that I am bring in and just displaying that for the buyer to reference. If the purchase price is more then the standard cost we have listed, a warning should appear to alert them that they are paying more. that part is working as it should.

I just ran a a test with a message to appear and it is showing the message twice, as if it is entering into the method multiple times.

So the std cost stays the same and you are changing the purchase cost on the screen, it should be able to compare the two properly.
As a warning for your code, you are executing the BAQ every time any field changes…

That BAQ is only bringing back a calculated field, and just for that one part, I don’t think it will impact the system to much, but, will this impact during PO suggestions?