Updateable BAQ in customisation error: Can't find query definition in passed dataset

Hi Guys

I’ve got an updateable BAQ that I’m calling from a customisation. The updateable BAQ works correctly in the BAQ editor but I’m getting an exception (Can’t find query definition in passed dataset) when calling the queryAdapter.Update method from a customisation.

I have the following code:

DynamicQueryAdapter queryAdapter = new DynamicQueryAdapter (oTrans);
queryAdapter.BOConnect();


QueryExecutionDataSet dataSet = queryAdapter.GetQueryExecutionParametersByID("BAQName");
dataSet.ExecutionParameter.Clear();
dataSet.ExecutionParameter.AddExecutionParameterRow("OrderNum", orderNum.ToString(), "int", false, Guid.Empty, "A");

queryAdapter.ExecuteByID("BAQName", dataSet);

if (queryAdapter.QueryResults.Tables["Results"].Rows.Count > 0)
{
	foreach (DataRow item in queryAdapter.QueryResults.Tables["Results"].Rows)
	{
		item["OrderHed_ShortChar05"] = userName;
		item["OrderHed_CheckBox01"] = 1;
		item["OrderHed_Date01"] = DateTime.Now;
		item["RowMod"] = "U";
	}
}

dataSet.AcceptChanges();
queryAdapter.Update(queryAdapter.DynamicQueryData, queryAdapter.QueryResults.Tables["Results"].DataSet, false);

I’ve tried calling the queryAdapter.Update method without arguments and it doesn’t error but it also doesn’t update the record.

Am I missing something here?

Many thanks!

ExecuteByID doesn’t return an updateable DataSet. You need to use Execute instead in the first part of the code, then Update will work correctly.

Thanks Darly, I’ve tried updating that with the following code but I get the same error (this time at the queryAdapter.Execute method call).

queryAdapter.Execute(queryAdapter.DynamicQueryData, dataSet);

I think it’s the queryAdapter.DynamicQueryData, when I look at it in the data visualisation tool in VS it’s empty, should I be populating this somewhere?

I’m assuming you actually put the name of the BAQ in here right?

Yes … I was getting deja vu, so I found this:

Apologies if this is something obvious but it looks like your setting the dsQuery to the termsAdapter.DynamicQueryData but I can’t see that termsAdapter being setup anywhere?

You assume correctly mate, it was just a meaningless name so I wanted it to be clearer.

I think this is going to keep coming back to bite me and I’d better go and edit that post …

It was a botched copy-and-paste, and “yourbaq” is defined at the top and “termsAdapter” should read “yourbaq” throughout. If you read down the thread you’ll see that’s already bitten someone else.

[Edit - I don’t seem to have an edit option on the old post, so it looks like I need to live with that mistake.]

Ah okay that makes sense (sorry I should’ve read the other posts).

I’ve updated the code to reflect yours but now I’me getting an interesting “Sequence contains no elements” exception when this bit of code is hit:

Ice.BO.QueryExecutionDataSet dsBAQ = yourbaq.GetQueryExecutionParameters(dsQuery);

What I’ve noticed though is that before that code is ran the code in the inner foreach loop (that creates a new target row) is never actually ran.

foreach (DataTable table in dsQuery.Tables)
				{
					foreach (DataRow sourceRow in dsQDesign.Tables[table.ToString()].Rows)
					{
						targetRow = table.NewRow();
						targetRow.ItemArray = sourceRow.ItemArray;
						table.Rows.Add(targetRow);
					}
				}

It looks like all the tables in dsQuery.Tables are actually empty. Could that be because a flag’s not checked in the BAQ or something?

For completion this is the current code I have (I’ve changed the last part to run the Update method but it’s not even hitting that part atm):

DynamicQueryAdapter yourbaq = new DynamicQueryAdapter(this.oTrans);
			DataTable results;
			yourbaq.BOConnect();
			
			
			string baqname = "BAQName";
			Ice.BO.DynamicQueryDataSet dsQuery = yourbaq.DynamicQueryData;
			if (dsQuery.DynamicQuery.Rows.Count == 0)
			{
				Ice.BO.DynamicQueryDataSet dsQDesign = yourbaq.QueryDesignData;
				DataRow targetRow;
				foreach (DataTable table in dsQuery.Tables)
				{
					foreach (DataRow sourceRow in dsQDesign.Tables[table.ToString()].Rows)
					{
						targetRow = table.NewRow();
						targetRow.ItemArray = sourceRow.ItemArray;
						table.Rows.Add(targetRow);
					}
				}
			}
			Ice.BO.QueryExecutionDataSet dsBAQ = yourbaq.GetQueryExecutionParameters(dsQuery);
			dsBAQ.ExecutionParameter[0].ParameterID = "OrderNum";
			dsBAQ.ExecutionParameter[0].IsEmpty = false;
			dsBAQ.ExecutionParameter[0].ParameterValue = orderNum.ToString();
			
			
			dsBAQ.AcceptChanges();
			yourbaq.Execute(dsQuery, dsBAQ);

I think it needs

yourbaq.GetByID("BAQNAME");

in there before the part you’re having trouble with. It’s looking increasingly like I should have taken a bit more time when I put that original post together.

Thanks for all your help Daryl! I had to add in the results code again but that works now!

You’ve really help me out there mate, not sure if I’d have been able to solve that on my own! :slight_smile: