Cannot Set A Value For Odbc.sqlstatement In 2016R1 Sdk 追蹤

Legacy Poster

First a disclaimer, I'm pretty new to BarTender and the SDK…

I seem to have run into a problem using the BarTender 2016R1 SDK and setting the SQL statement in an ODBC DatabaseConnection.
I'm thinking that I'm either missing something obvious here, or I've found a bug. Odds are I'm just missing something.
Would someone please point me in the right direction here?

I have a label file with a ODBC database connection configured.
I have an application that prints labels. This app opens the label file and updates the SQL statement to print just 1-3 items.

I've found that when I set the ODBC.SQLStatement and then print the label it won't use the SQLStatement that I just set. Instead will it will print a full set of labels using the default SQL statement for the database connection that's stored in the label file. I've reviewed several examples and posts and confirmed that pattern I'm using is correct.


What I'm finding odd is that I've walked through this with a debugger and found that ODBC.SQLStatement is always empty. In the below code snippet SQLStatement is empty in odbcConnection when it should have the SQL statement that's stored in the label file. It's also empty in btFormat.DatabaseConnections[0] after the call to SetDatabaseConnection().

What I'm finding interesting is that using the debugger I can assign sqlQuery to the private property m_database.SQLStatement and the label will print out the correct result set from sqlQuery. I've also confirmed this same private property in the DBConnection object retrieved from the label file does contain the original SQL statement while the value of ODBC.SQLStatement from the same file is empty.

Here's a code snippet detailing what I'm seeing.
var sqlQuery = string.Format("SELECT * FROM [MyDatabase].[dbo].[MyView] WHERE PartID = {0}", item.PartID);

var btFomat = Engine.Documents.Open(@"C:\tmp\test.btw");
btFormat.PrintSetup.PrinterName = _defaultPrinter;
btFormat.PrintSetup.UseDatabase = true;
btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
var dbConnection = btFormat.DatabaseConnections[0];

// This suggested code pattern doesn't work for me, and I've tried several variations.
var odbcConnection = (ODBC)btFormat.DatabaseConnections[0];
var newConnection = new ODBC(odbcConnection.Name) { SQLStatement = sqlQuery };

// This reflection code does work
var m_database = dbConnection.GetType().GetField("m_database", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(dbConnection);
var sqlStatement = m_database.GetType().GetProperty("SQLStatement").GetValue(m_database);
m_database.GetType().GetProperty("SQLStatement").SetValue(m_database, sqlQuery);


1 意見

Legacy Poster
評論操作 永久連結

I've just confirmed that this issue is resolved in the 2016R2 SDK..


Also - A big thanks to their technical specialist Tyler.