0
我已經成功地在webmatrix中使用iTextSharp生成pdf。我有如下所示的查詢:在iTextSharp中的單元格中插入查詢值
var db = Database.Open("Northwind");
var sql = "SELECT CustomerID, CompanyName, ContactName, Address, City, Country, Phone FROM Customers WHERE CustomerID = 'ALFKI'";
var data = db.Query(sql);
在我的PDF我想插入我在那裏打上我的代碼#query和#QUERY2查詢值。
dfPTable nestedb = new PdfPTable(2);
nestedb.DefaultCell.Border = 0;
nestedb.AddCell(new Phrase("Company Name:", arialCertify));
nestedb.AddCell(new Phrase(#query));
nestedb.AddCell(new Phrase("Contact name:", arialCertify));
nestedb.AddCell(new Phrase("#query2", arialCertify));
如何在我生成的pdf中插入查詢值?
非常感謝。在這個鏈接http://www.mikesdotnetting.com/Article/205/Exporting-The-Razor-WebGrid-To-PDF-Using-iTextSharp的幫助下,pdf隨着數據隨時生成。我不知道獲取我的數據庫值的語法,只需將它們插入到我的pdf中的相應部分即可。 –
迭代數據變量,並且對於每個'customer'元素,您可以訪問'customer.CompanyName','customer.ContactName' –
當我迭代並使用customer.CustomerName或data.CustomerName時,我的pdf不會生成我的代碼中有錯誤。是否有可能向我提供代碼。我的查詢結果是單個記錄。 –