Hi Vishal,
Thanks for considering Aspose.
Please see the following code that reads the customer data from the SQL database and generates the barcode for each customer. It generates BarCode for "CustomerCode" field of "Customer" table. I have tested it by setting the customer code to "UNWAC TAB character 0123456789" in the DB. Please let me know if it works for you or I can be of further assistance.
// open connection to DB
SqlConnection conn = new SqlConnection("Server=server;Database=DBName;Trusted_Connection=True;");
conn.Open();
// select records from customer table and open the reader
SqlCommand cmd = new SqlCommand("SELECT * FROM Customer", conn);
SqlDataReader reader = cmd.ExecuteReader();
string strCustomerCode = "";
// iterate through all the records in the reader
while (reader.Read())
{
// get the customer code in variable
strCustomerCode = reader[
"CustomerCode"].ToString();
// create the barcode object and set the codetext and symbology
BarCodeBuilder barcode = new BarCodeBuilder(strCustomerCode, Symbology.Code128);
// enable escape sequences to be encoded e.g. \n, \t etc
barcode.EnableEscape =
true;
// generate the barcode image
barcode.GenerateBarCodeImage();
// save in some file. You can also save in stream
barcode.Save(
@"c:\temp\customer.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
}
// clean up DB resources
reader.Close();
cmd.Dispose();
conn.Dispose();
Best Regards,
Saqib Razzaq
Support Developer
Aspose Guangzhou Team