Setting a Text Field Value to BAQ Result?

Hey all,

I followed a tutorial by Jose to pass parameters to a BAQ using a Dynamic Query and got it succesfully working based on the Part Number field.

For the sake of cleaning it up and making the form look better, I would like to set the Result to a text field instead of an UltraGrid (each part should only have one row returned)

Here is an example of the code:

private void IssueReturn_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
// ** Argument Properties and Uses **
// args.Row[“FieldName”]
// args.Column, args.ProposedValue, args.Row
// Add Event Handler Code
switch (args.Column.ColumnName)
{
case “PartNum”:
break;
}

  		Control txtPart = csm.GetNativeControlReference("b4419292-dab8-4fe1-8e0c-6dbf6dd9e971");
  		string pnum = txtPart.Text;
  		DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
  			dqa.BOConnect();
  			QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("BAQ");
  			qeds.ExecutionParameter.Clear();
  			qeds.ExecutionParameter.AddExecutionParameterRow("PartParam", pnum , "nvarchar", false, Guid.NewGuid(),"A");
  			dqa.ExecuteByID("BAQ",qeds);
  			epiUltraGridC1.DataSource = dqa.QueryResults.Tables["Results"];

}
}

I wasn’t having much luck passing it as a string (which makes sense, I’m just not sure how to convert the first row to string and set a textbox value to it.

Edit: All the BAQ does is get the get the vendor number based from the PartXRefVend table

You may be better off here using FKV Foreign Key View if all you want to do is get the Vendor Number

1 Like

Do the User Guides have any examples of referencing a foreign key value?

:slight_smile:

Thanks for the help!

Edit: I’m looking at the custom views for the FKV, but I’m not seeing where it will allow me to attach the PartXRefvend.VendPartNum

Heyho,

I was building somehthing like this to, where it gave me the PerCon.Name which belongs to the passed PerConID.

My Script looked something like this:

DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
dqa.BOConnect();
QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID(“serno_contact”);
qeds.ExecutionParameter.Clear();
qeds.ExecutionParameter.AddExecutionParameterRow(“ParPerConID”, txtPerConID_c.Text, “int”, false, Guid.NewGuid(), “A”);
dqa.ExecuteByID(“serno_contact”, qeds);

if(dqa.QueryResults.Tables["Results"].Rows.Count == 0){
	MessageBox.Show("Unable to find Contact");
	txtPerConID_c.Text = "0";
	txtName_c.Text = ""; 
}
				
foreach(DataRow row in dqa.QueryResults.Tables["Results"].Rows){
	
	if(txtName_c.Text != row["PerCon_Name"].ToString()){
		MessageBox.Show("ContactID does no fit to the Contact name. Updating Contact name now! ");
		
		EpiDataView edvSerialNo = ((EpiDataView)(this.oTrans.EpiDataViews["SerialNo"]));
		System.Data.DataRow edvSerialNoRow = edvSerialNo.CurrentDataRow;
		
		if ((edvSerialNoRow != null)){
			edvSerialNoRow.BeginEdit();
			edvSerialNoRow["Name_c"] = row["PerCon_Name"];
			edvSerialNoRow.EndEdit();
			}
		}	
	}	

I the last few lines you can see that i am not setting the txt Field. But you might be able to do it anyway by replacing the whole epidataview thing with:

epiTextField.Text = row[“VenderNum”].ToString();

Or Something like that :slight_smile:

I need to look at your code a bit more in depth, as I have not yet used an EpiDataView. The code we ended up using looked like this, and it seemed to work.

try
{
				Control txtPart = csm.GetNativeControlReference("b4419292-dab8-4fe1-8e0c-6dbf6dd9e971");
				string pnum = txtPart.Text;
				DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
					dqa.BOConnect();
					QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("BAQHere");
					qeds.ExecutionParameter.Clear();
					qeds.ExecutionParameter.AddExecutionParameterRow("PartParam", pnum , "nvarchar", false, Guid.NewGuid(),"A");
					dqa.ExecuteByID("BAQHere",qeds);
					tbSupNum.Text = dqa.QueryResults.Tables[0].Rows[0][0].ToString();
}
catch (Exception ex)
{
}