数据显示在PDF中

时间:2013-09-16 05:26:41

标签: c# asp.net pdf

//工作细节

       PdfPTable tabl2 = new PdfPTable(7);
               // tabl2.TotalWidth = 350f;
                //tabl2.LockedWidth = true;
                //tabl2.HorizontalAlignment = 0;
                tabl2.SpacingBefore = 10f;
                bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
                times = new Font(bfTimes, 12f, Font.UNDERLINE);
                para = new Paragraph("Working Details:", times);
                para.Alignment = Element.ALIGN_LEFT;
                doc.Add(para);
                cell.Colspan = 3;
                cell.Rowspan = 2;
                cell.HorizontalAlignment = 0;
                cell.BorderColor = new BaseColor(0, 0, 0);
                //tabl2.AddCell(new Phrase("Sr.No.", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));

                tabl2.AddCell(new Phrase("Working Place", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl2.AddCell(new Phrase("Date Of Joining", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl2.AddCell(new Phrase("Institute Name", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl2.AddCell(new Phrase("Year", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl2.AddCell(new Phrase("Duration", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl2.AddCell(new Phrase("Post held at last", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl2.AddCell(new Phrase("Area of Work", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                string connects = @"Data Source=BOPSERVER;Initial Catalog=Project;Integrated Security=True";
                using (SqlConnection cn = new SqlConnection(connects))
                {
                    string query = "select * from Working_det where Fid='" + va+"'";
                    SqlCommand cmd = new SqlCommand(query, cn);
                    try
                    {
                        cn.Open();
                        using (SqlDataReader sdr = cmd.ExecuteReader())
                        {
                            while (sdr.Read())
                            {


                                tabl2.AddCell(new Phrase(sdr[1].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl2.AddCell(new Phrase(Convert.ToDateTime(sdr[2]).ToShortDateString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl2.AddCell(new Phrase(sdr[3].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl2.AddCell(new Phrase(sdr[4].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl2.AddCell(new Phrase(sdr[5].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl2.AddCell(new Phrase(sdr[6].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl2.AddCell(new Phrase(sdr[7].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                    }
                }

                cell.Rowspan = 2;
                cell.Colspan = 2;
                tabl2.AddCell(cell);
                tabl2.SpacingAfter = 30f;
                doc.Add(tabl2);


                //Membership Details
                PdfPTable tabl3 = new PdfPTable(4);
                tabl3.SpacingBefore = 10f;
                bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
                times = new Font(bfTimes, 12f, Font.UNDERLINE);
                para = new Paragraph("Membership Details:", times);
                para.Alignment = Element.ALIGN_LEFT;
                doc.Add(para);
                cell.Colspan = 3;
                cell.Rowspan = 2;
                cell.HorizontalAlignment = 0;
                cell.BorderColor = new BaseColor(0, 0, 0);
                tabl3.AddCell(new Phrase("Membership Number", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl3.AddCell(new Phrase("Type of Membership", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl3.AddCell(new Phrase("Validity", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                tabl3.AddCell(new Phrase("Remarks", FontFactory.GetFont("Arial", 8, Font.BOLD, BaseColor.BLACK)));
                string connect = @"Data Source=BOPSERVER;Initial Catalog=Project;Integrated Security=True";
                using (SqlConnection cn = new SqlConnection(connect))
                {
                    string query = "select * from Membership_det where Fid=='" + va + "'";
                    SqlCommand cmd = new SqlCommand(query, cn);
                    try
                    {
                        cn.Open();
                        using (SqlDataReader sdr = cmd.ExecuteReader())
                        {
                            while (sdr.Read())
                            {

                                tabl3.AddCell(new Phrase(sdr[1].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl3.AddCell(new Phrase(sdr[2].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl3.AddCell(new Phrase(sdr[3].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                                tabl3.AddCell(new Phrase(sdr[4].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK)));
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Response.Write(ex.Message);
                    }
                }
                cell.Rowspan = 2;
                cell.Colspan = 2;
                tabl3.AddCell(cell);
                tabl3.SpacingAfter = 30f;
                doc.Add(tabl3);

以上代码显示以PDF格式显示数据。 我的问题是pdf数据将显示工作细节,但不会显示会员资格详情.. pdf如下所示。我需要检查会员资料的数据,因为它已显示在工作细节中

代码没有变化,但没有检索到数据。请为此提出任何帮助..

Pdf for the following code

1 个答案:

答案 0 :(得分:2)

通过快速检查您的代码,您的第二个查询似乎没有得到任何响应。确保您的数据库中包含查询数据,并且查询返回您期望的数据。