Rik
(Richard Hodges)
November 25, 2019, 2:46pm
1
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!
dhewi
(Daryl Hewison)
November 25, 2019, 3:03pm
2
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.
Rik
(Richard Hodges)
November 25, 2019, 3:12pm
3
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?
Banderson
(Brandon Anderson)
November 25, 2019, 3:26pm
4
I’m assuming you actually put the name of the BAQ in here right?
dhewi
(Daryl Hewison)
November 25, 2019, 3:26pm
5
Yes … I was getting deja vu, so I found this:
OK, here’s the core code we use - I’ll detail some things to note after it:
DynamicQueryAdapter yourbaq = new DynamicQueryAdapter(this.oTrans);
DataTable results;
yourbaq.BOConnect();
string baqname = "BAQNAME";
Ice.BO.DynamicQueryDataSet dsQuery = termsAdapter.DynamicQueryData;
if (dsQuery.DynamicQuery.Rows.Count == 0)
{
Ice.BO.DynamicQueryDataSet dsQDesign = termsAdapter.QueryDesignData;
DataRow targetRow;
foreach (DataTable table in dsQuery.Tables)
{
foreach (DataRow sourceRow in dsQDe…
Rik
(Richard Hodges)
November 25, 2019, 3:39pm
6
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?
Rik
(Richard Hodges)
November 25, 2019, 3:40pm
7
You assume correctly mate, it was just a meaningless name so I wanted it to be clearer.
dhewi
(Daryl Hewison)
November 25, 2019, 3:42pm
8
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.]
Rik
(Richard Hodges)
November 25, 2019, 3:59pm
9
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);
dhewi
(Daryl Hewison)
November 25, 2019, 4:09pm
10
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.
Rik
(Richard Hodges)
November 26, 2019, 9:00am
11
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!