111,098
社区成员




SystemDatabaseConnection connection = new SystemDatabaseConnection();
connection.Method = SystemDatabaseConnectionMethod.Manual;
connection.Authentication = SystemDatabaseAuthenticationMethod.SQLServer;
connection.ServerName = @"DELL-PC";
connection.DatabaseName = "生产部自动派号数据库";
connection.UserName = "sa";
connection.Password = "sql";
connection.Connect();
string sqlcommand = "select MAC号 from " + dbs.ToString() + " where MAC号 between '" + FirstMAC + "' and '" + LastMAC + "'";
OLEDB oledb = new OLEDB("MyDataBase");
oledb.SQLStatement = sqlcommand;
LabelFormatDocument format = mybtEngine.Documents.Open(@txt_FormatPath.Text.Trim());
format.DatabaseConnections.SetDatabaseConnection(oledb);
format.Print();
format.Close(SaveOptions.DoNotSaveChanges);
mybtEngine.Stop();
In order to use the System Database SDK, you must establish a connection with a BarTender System Database in order to access information saved by applications in the BarTender Suite. A connection to the BarTender System Database is made using the SystemDatabaseConnection class.
The following code demonstrates how to automatically connect to the BarTender System Database using the settings specified in the BarTender System Database Setup dialog.
In C#:
try
{
SystemDatabaseConnection connection = new SystemDatabaseConnection();
connection.Connect();
}
catch (SystemDatabaseConnectionException ex)
{
// Handle can't connect or database not configured exceptions
}
To manually connect to a BarTender System Database, you must specify the following connection parameters:
The location of the SQL server database, using the ServerName property;
The name of the BarTender System Database, using the DatabaseName property;
The type of user authentication (Windows or SQL), using the Authentication property.
(Only when using SQL Server Authentication) Login credentials, using the UserName and Password properties.
The following code demonstrates how to manually configure a connection to a BarTender System Database using SQL server authentication.
In C#:
try
{
SystemDatabaseConnection connection = new SystemDatabaseConnection();
connection.Method = SystemDatabaseConnectionMethod.Manual;
connection.Authentication = SystemDatabaseAuthenticationMethod.SQLServer;
connection.ServerName = @"MyServer\BarTender";
connection.DatabaseName = "BarTender";
connection.UserName = "MyUserName";
connection.Password = "MyPassword123";
// Connect to the BarTender System Database
connection.Connect();
}
catch (SystemDatabaseConnectionException ex)
{
// Handle can't connect or database not configured exceptions
}
USE [生产部自动派号数据库]
GO
/****** Object: StoredProcedure [dbo].[sp_GetDBVersion] Script Date: 03/10/2016 10:03:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*---------------------------------------------------------------------------*/
/* Procedure: sp_GetDBVersion */
/* Purpose: Return the Hard-Coded Database Version via an Output variable*/
/* NOTE: This stored procedure was kept for backwards compatibility */
/* with BSS 1.0, and should be left alone- the Version number */
/* should NOT be altered here. Change SpGetDBVersion instead. */
/*---------------------------------------------------------------------------*/
CREATE PROCEDURE [dbo].[sp_GetDBVersion](@Version INTEGER OUTPUT, @DbDescription NCHAR(100) OUTPUT)
AS
SELECT @Version = 150, @DbDescription = N'This is the initial version of the Database'
GO
这个地方Version=150。是跟数据库版本有关系,我用的是SQL Server2008,写成100的话,会报错,在调用BarTender的DLL时会提示数据库版本不一样。
第二步:在BarTender的标签模板中,为需要套打数据的控件(主要是条形码控件),绑定数据源,也就是数据库字段。
第三步:
打印代码实际上只需要
string sqlcommand = "select MAC号 from " + dbs.ToString() + " where MAC号 between '" + FirstMAC + "' and '" + LastMAC + "'";
OLEDB oledb = new OLEDB("MyDataBase");
oledb.SQLStatement = sqlcommand;
LabelFormatDocument format = mybtEngine.Documents.Open(@txt_FormatPath.Text.Trim());
format.DatabaseConnections.SetDatabaseConnection(oledb);
format.Print();
这一段就可以。