Skip to main content

Search

Search

Control Bartender Involve Database Using C#

Comments

4 comments

  • Avatar
    Susan Chen
    Moderator
    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



    Thanks!
    0
  • Avatar
    Legacy Poster
    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.

    [code]
    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);
    btFormat.Close(BarTender.BtSaveOptions.btSaveChanges);
    }
    [/code]

    Any help would be really appreciated.Thanks.
    0
  • Avatar
    Legacy Poster
    Hi 
     
    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 + "'";
            this.btFormat.PrintOut();
     
    0
  • Avatar
    Domingo Rodriguez
    Moderator

    Tbzserge,

     

    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

    0

Please sign in to leave a comment.