1

I have a web application which at the moment generates certificates using a template. Since I original wrote it in php, I used the str_replace built in function to replace values in my template with values from the query.

Now I have changed to asp.net web pages and my aim is to generate certificates in pdf and mail them.

I am using iTextSharp and webmatrix.

Below is part of my code :

 var sql = "SELECT CustomerID, CompanyName, ContactName, Address, City, Country, Phone FROM Customers WHERE CustomerID = 'ALFKI'";
var data = db.Query(sql);

  foreach(var item in data){ var companyname = item.CompanyName;}

PdfPCell certify1 = new PdfPCell(new Phrase("companyname"));
certify1.Colspan = 2;
certify1.Border = 0;
certify1.PaddingTop = 40f;
certify1.HorizontalAlignment = 1;//0=Left, 1=Centre, 2=Right
table.AddCell(certify1);

From this code I am trying to show the data from database table. The code above is not working. I am trying to grab the query values and have then in certify1 cell. How can I do this?

Sithelo Ngwenya
  • 501
  • 2
  • 10
  • 28
  • Thanks for your question! However, this is not really the kind of question that Stack Overflow is here to answer. [Read this for more information](http://stackoverflow.com/faq#dontask) Once you have a specific question about a specific problem you are having with code you are writing, feel free to return. – Andrew Barber Mar 05 '13 at 01:54
  • @Mike-Brind I have added code and interested in showing values from query. The query returns a single value. – Sithelo Ngwenya May 16 '13 at 12:31

1 Answers1

0

Try this:

var sql = "SELECT CustomerID, CompanyName, ContactName, Address, City, Country, Phone FROM Customers WHERE CustomerID = 'ALFKI'";
var data = db.Query(sql);

foreach(var item in data){ 
    var companyname = item.CompanyName;
    PdfPCell certify1 = new PdfPCell(new Phrase(companyname));
    certify1.Colspan = 2;
    certify1.Border = 0;
    certify1.PaddingTop = 40f;
    certify1.HorizontalAlignment = 1;//0=Left, 1=Centre, 2=Right
    table.AddCell(certify1);
}
Volodymyr
  • 1,209
  • 1
  • 15
  • 26