Print Datatable Or Datagridview Follow

0
Avatar
Legacy Poster

Hi, I need to print labels from a datatable or datagridview in Visual Basic.

 

To print a single line using the following code:


Using

btEngine As New Engine()

' Start the BarTender print engine.

btEngine.Start()

' Open a format document.

Dim btFormat As LabelFormatDocument

btFormat = btEngine.Documents.Open("C:\Label1.btw", "NamePrinter")

 

' Set substrings to new values.

btFormat.SubStrings.SetSubString("Name1", "Date1")

btFormat.SubStrings.SetSubString("Name2", "Date2")

btFormat.SubStrings.SetSubString("Name3","Date3"))

btFormat.Print()

' Close the current format without saving.

btFormat.Close(SaveOptions.DoNotSaveChanges)

' Stop the BarTender print engine.

btEngine.Stop()

End Using

What would be

 

To send from a datatable?

Thanks

2 comments

0
Avatar
Fernando Ramos Miracle
Moderator
Comment actions Permalink

Hello Miguel,

 

There are different methods of printing labels sourcing information form a datatable or database, although you won't need the use of the "Substring" class. Basically you'll need to design your label document to read the information from the required database type.

 

BarTender documents can be designed to read data from one or more database connections such as text files, OLE DB, or ODBC. Database connection settings are configured using a LabelFormat's DatabaseConnections collection. Each DatabaseConnection contained in the collection contains settings specific to the database type. 
 
Please visit BarTender's Help documentation and search for the "Automating Database Printing" document, as it fully describes how to do what you are looking for.
 
Below you'll find a simple example when using a text file as database:
 

 

Imports Seagull.BarTender.Print.Database
' Application Code 
' ... 
Dim btEngine As New Engine()
' Start a BarTender print engine 
btEngine.Start()
' Open a label format 
Dim btFormat As LabelFormatDocument = btEngine.Documents.Open("c:\MyLabel.btw")
' Set the TextFile database connection file name 
CType(btFormat.DatabaseConnections("TextFileDB"), TextFile).FileName = "c:\NutritionInformationEurope.txt"
' Print the label format document 
btFormat.Print()
' Stop the engine 
btEngine.Stop()

 

Regards
0
Avatar
Legacy Poster
Comment actions Permalink

Hi,

 

I am just starting out with BarTender, right now I am using Crystal Reports and VS 2010 C# to design a complex Prescription label with multiple barcodes etc. and printing to a Zebra 110Xi4 printer

and the Data Source I send to the report (Label) is a Data Table created and populated at Run Time

 

but now I want to start with BarTender, but nowhere can I find an answer on If its possible to send the Data Table at run time to the BarTender document, the post above was the closest I got to this answer, but still all you said is that all types of Database connections can be made, but I don't want a database or a file or even XML to be the DB connection and source, I want to send a DataTable

 

is this possible with BarTender, and can you give me an example of how?

 

Thank you

David

Please sign in to leave a comment.