Zum Hauptinhalt gehen

Suche

Suche

Substring

Kommentare

3 Kommentare

  • Avatar
    Shotaro Ito
    Hi Jiji,
    With SubStrings Value method you cannot print two or more records, as setting value just overwrites previous value before print.
    What you can do is, design label format to use text database (CSV etc).
    From C# app, create temp CSV File with desired records, apply the file by SetDatabaseConnection method.
    This way you can print multiple records in one job, so it will take multi-column labels.

    [code] // Start the BarTender print engine.
    btEngine.Start();

    // Create an instance of TextFile
    TextFile textFile = new TextFile("TextfileDatabase");

    // Provide a path to the text file.
    textFile.FileName = @"C:\TextfileDatabase.txt";

    // Initialize the format document
    // (create a format with query prompts to use this example).
    LabelFormatDocument btFormat = btEngine.Documents.Open(@"C:\FormatWithQueryPrompts.btw");

    // Set the database connection created above.
    btFormat.DatabaseConnections.SetDatabaseConnection(textFile);

    // Print the format.
    btFormat.Print();

    [/code]
    0
  • Avatar
    Legacy Poster
    Thanks Shotaro.

    [b]How can I design label format to use text database (CSV etc). And in text file how can I place data.?[/b]

    [indent]With the help of BarTender Software I created one Label.

    First I connected to my database and drag one field to Label and Saved it.

    But Then, I don't know, in text file which order I want to place data.

    I just put some data separated by comma. But after running c# code it is showing the error "Database types do not match"
    [/indent]
    Can you please give me the procedure in detail.
    0
  • Avatar
    Shotaro Ito
    Hi Jiji,
    First you need to create a label format which has CSV data connection.

    Say you have a text file like this: ("C:\sample.csv")
    [code]"FNAME","LNAME","DOB"
    "Sam","Sampleton","1962/07/03"
    "Samir","Samproski","1965/01/24"[/code]
    first line has list of field names (each fields are quoted by ""), following lines are 2 records of dummy data (and so on.)

    Following [url="http://www.seagullscientific.com/aspx/training-video-(reading-data-from-database).aspx"]how to create excel database connection[/url], you can create Text database connection to the text file, with select Delimitation type as "Mixed Quote and Comma" (which means CSV) and First record is "header" to [Yes].
    Associate some text's datasource to database fields, and print preview to see 2 labels will be printed.
    Save the format (such as "C:\FMT1.BTW")

    In .net SDK, you can assign text database by SetDatabaseConnection() method like below:

    [code]
    // Open format at same folder as executable
    btFormat = btEngine.Documents.Open(Application.StartupPath + @"\FMT1.btw");
    //btFormat.PrintSetup.PrinterName("Zebra TLP3844-Z"); // specify printer

    // Prepare data (you can be more creative.)
    string buf = "";
    buf += "\"FNAME\",\"LNAME\",\"DOB\"\r\n"; // header
    buf += "\"Steven\",\"Jobs\",\"1955/02/24\"\r\n"; //record 1
    buf += "\"Stephen\",\"Wozniak\",\"1950/08/11\"\r\n";
    buf += "\"John\",\"Sculley\",\"1939/04/06\"\r\n";
    buf += "\"Gilbert\",\"Amerio\",\"1943/03/01\"\r\n";

    // Create text database as a temporary file
    string tmpFile = Path.GetTempFileName();
    File.WriteAllText (tmpFile, buf);

    // Assign the text database to curtent format's primary database
    Seagull.BarTender.Print.Database.TextFile tf = new Seagull.BarTender.Print.Database.TextFile(btFormat.DatabaseConnections[0].Name);
    tf.FileName = tmpFile;
    btFormat.DatabaseConnections.SetDatabaseConnection(tf);
    btFormat.PrintSetup.ReloadTextDatabaseFields = true; // Fix when field order is different from design time

    // Print
    btFormat.Print();

    // Delete text database
    File.Delete(tmpFile);[/code]

    I've posted a [url="http://seagullscientific.invisionzone.com/index.php?/topic/525-sample-code-create-and-assign-csv-database/"]sample project[/url] so please check that.
    0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.