Control Bartender Involve Database Using C# Follow


Hi there.I'm using Bartender Automation enterprise 9.4 as well as Microsoft Visual Studio 2005 to help me on my project.

I'm using C# language to design a program and controlling bartender. When it prints,it will call the bartender format and prints out the label that i desire.I have done this part and it works perfectly.

But,what if my bartender involves connect to database(in my case,which is SQL server 2000) to get the data?
Do i need to set the connection on my C# program or the bartender will connect itself when the program is running?

Maybe some one can guide me what can i do starting from this part?
I need to like checking the input from user,check whether it's in database or not.
If so,it will return another field data which is on the same row.
If not, a validation message will appear.That's all.

Thanks.Any help would be really appreciated.


Susan Chen
Comment actions Permalink

Dear Tbzserge :

You setup the database connection inside Bartender: File-> Database Connection Setup. In ActiveX, you can reference Bartender Help-> Automating Bartender-> Automation with ActiveX-> Examples using ActiveXAutomation-> Automating Database Printing in C#

//Declare a BarTender application variable

BarTender.Application btApp;

//Declare a BarTender format variable

BarTender.Format btFormat;

//Declare a BarTender database variable

BarTender.Database btDb;

//Instantiate a BarTender application variable

btApp = new BarTender.ApplicationClass();

//Open the BarTender label format

btFormat = btApp.Formats.Open("c:\\Format1.btw", false, "");

//Select the database

btDb = btFormat.Databases.GetDatabase(1);

//Set the SQL statement

btDb.OLEDB.SQLStatement = "SELECT * FROM 'Customers' WHERE 'Name'='Frank Wild'";

You can extract data from database field or show some message depend on your result.

Hope it helps

Legacy Poster
Comment actions Permalink

Hi Susan,

Actually, i still haven't get myself clear how to retrieve the data from the database (which is connected to bartender) using programming language.

I have tried the code which i refer to bartender ActiveX Automation White Paper.It works perfectly on how to call bartender format and print.

I have done a small test to help me do so.

I have created 2 button,one is call cmdCheck and another one is cmdPrint and 1 textbox call txt1. My database name is Database1 ,table name is Solder_Paste.

I just want to have a test when clicking the check button,it will run the syntax and search from the table and return the result in txt1 and print it when print button is clicked.I have checked the SQL syntax in SQLserver.It works fine.

private void cmdCheck_Click(object sender, EventArgs e)
BarTender.Database btDb;

btDb = btFormat.Databases.GetDatabase(1);
btDb.OLEDB.SQLStatement = "SELECT 'PartNumber' FROM 'Solder_Paste' WHERE 'GRNNumber' = '1234567'";
txt1.Text = btDb.OLEDB.SQLStatement;

private void cmdPrint_Click(object sender, EventArgs e)
btFormat = btApp.Formats.Open("C:\\Documents and Settings\\Desktop\\vb3\\Format1.btw", false, "");
btFormat.SetNamedSubStringValue("testing", txt1.Text);
btFormat.Print("Job1", true, -1, out btMsgs);

Any help would be really appreciated.Thanks.
Legacy Poster
Comment actions Permalink

Please i need help I am using bartender full suit 10.1 

in below code when i assign the value of "btDataBase.ODBC.Password" it cann't got it but in case of "btDataBase.ODBC.UserId" or "this.btDataBase.ODBC.SQLStatement" there values changed Please help me in this i am new in this..
        btDataBase =btFormat.Databases.GetDatabase(1);
        btDataBase.ODBC.UserId = mUserID;
        btDataBase.ODBC.Password = mPassword;
        this.btDataBase.ODBC.SQLStatement = "SELECT * from ScannedData WHERE PackingID='" + l_PackingID + "'";
Domingo Rodriguez
Comment actions Permalink



When you run the cmdCheck_Click and cmdPrint_Click, what is the value for "testing" when it does get printed?


I'm not 100% sure of what you're wishing to achieve. If you just want BarTender to connect to the database, perform an SQL Statement (or assigning a query prompt value), then the example Susan already sent you is the one to be used (to be followed by the Print() method if you're wishing to print those labels which result from applying the SQL Statement / query prompt value). If you're still having issues, please describe in more detail what is going on exactly.


By the way, if you're using C#.Net, you would be better make use of the .NET SDKs

Please sign in to leave a comment.