2014-04-14 2 views
0
PdfPTable tabl11 = new PdfPTable(8); 
      string connect19 = ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ConnectionString; 
      SqlConnection cn19 = new SqlConnection(connect19); 
      cn19.Open(); 
      SqlCommand cmd19 = new SqlCommand("select distinct * from (select p1.PubID,p2.Publisher,p2.Title,p.name as authors from Personal_det p,Publication_Tracker p1,Publication_det p2 where p.FID=p1.FID and p1.Contribution_Type='A' and p1.PubID=p2.PubID and [email protected]) t1 inner join (select p.Name as coauthors,p2.PubID,p2.Type,p2.Title,p2.PubDate,p2.Publisher from Personal_det p,Publication_Tracker p1,Publication_det p2 where p.FID=p1.FID and p1.Contribution_Type='C' and p1.PubID=p2.PubID and p1.PubID=4) t2 on t1.PubID = t2.PubID ", cn19); 
      cmd19.Parameters.AddWithValue("@FID", Session["FID"]); 
      SqlDataReader rdr11 = cmd19.ExecuteReader(); 
      if (!rdr11.Read()) 
      { 
       tabl11.DeleteBodyRows(); 
       cn19.Close(); 
      } 
      else 
      { 
       tabl11.SpacingBefore = 10f; 
       bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false); 
       times = new Font(bfTimes, 12f, Font.UNDERLINE); 
       para = new Paragraph("Publication:", 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); 
       tabl11.AddCell(new Phrase("Pub ID", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 
       tabl11.AddCell(new Phrase("Publisher", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 
       tabl11.AddCell(new Phrase("Title", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 
       tabl11.AddCell(new Phrase("Authors", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 
       tabl11.AddCell(new Phrase("Co-Authors", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 
       tabl11.AddCell(new Phrase("Type", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 
       tabl11.AddCell(new Phrase("Title", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 
       tabl11.AddCell(new Phrase("Publication Date", FontFactory.GetFont("Arial", 12, Font.BOLD, BaseColor.BLACK))); 

       string connect6 = ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ConnectionString; 
       using (SqlConnection cn = new SqlConnection(connect6)) 
       { 
        string query = "select * from (select p1.PubID,p2.Publisher,p2.Title,p.name as authors from Personal_det p,Publication_Tracker p1,Publication_det p2 where p.FID=p1.FID and p1.Contribution_Type='A' and p1.PubID=p2.PubID ) t1 inner join (select p.Name as coauthors,p2.PubID,p2.Type,p2.Title,p2.PubDate from Personal_det p,Publication_Tracker p1,Publication_det p2 where p.FID=p1.FID and p1.Contribution_Type='C' and p1.PubID=p2.PubID ) t2 on t1.PubID = t2.PubID "; 
        SqlCommand cmd = new SqlCommand(query, cn); 
        try 
        { 
         cn.Open(); 
         using (SqlDataReader sdr = cmd.ExecuteReader()) 
         { 
          while (sdr.Read()) 
          { 
           tabl11.AddCell(new Phrase(sdr[0].ToString(), FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK))); 
           tabl11.AddCell(new Phrase(sdr[1].ToString(), FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK))); 
           tabl11.AddCell(new Phrase(sdr[2].ToString(), FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK))); 
           tabl11.AddCell(new Phrase(sdr[3].ToString(), FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK))); 
           tabl11.AddCell(new Phrase(sdr[4].ToString(), FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK))); 
           tabl11.AddCell(new Phrase(sdr[5].ToString(), FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLACK))); 
           tabl11.AddCell(new Phrase(sdr[6].ToString(), FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK))); 
           tabl11.AddCell(new Phrase(Convert.ToDateTime(sdr[7]).ToShortDateString(), FontFactory.GetFont("Arial", 10, Font.NORMAL, BaseColor.BLACK))); 

          } 
         } 
        } 
        catch (Exception ex) 
        { 
         Response.Write(ex.Message); 
        } 
       } 

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

이 위의 코드는 내가오류 동안

select * from 
(select p1.PubID,p2.Publisher,p2.Title,p.name as authors 
from Personal_det p,Publication_Tracker p1,Publication_det p2 
where p.FID=p1.FID and p1.Contribution_Type='A' and p1.PubID=p2.PubID ) t1 
inner join 
    (select p.Name as coauthors,p2.PubID,p2.Type,p2.Title,p2.PubDate 
    from Personal_det p,Publication_Tracker p1,Publication_det p2 
    where p.FID=p1.FID and p1.Contribution_Type='C' and p1.PubID=p2.PubID ) t2 
    on t1.PubID = t2.PubID 

사용하는 것을 위의 질의 나누었다 PDF의 데이터베이스 열을 표시하는 데 사용 네 개의 행을 가지고 있습니다 그러나 PDF에 표시하는 동안 one 행만 표시됩니다. 해결 방법은 무엇입니까? 어떤 도움을 주셔서 감사합니다.

+2

라인'PdfPTable tabl11 = 새로운 PdfPTable (8),'8 열 테이블을 생성하지만, 귀하의 의견은 데이터베이스가 4 열이 있다고 말한다. 또한 "네 개의 열이 있지만 PDF에 표시하는 동안 단 하나의 행만 표시됩니다"라고 말합니다. 열의 수는 행의 수에 영향을 미치지 않으므로 문제를 더 잘 설명해야합니다. 'cell' 변수는 무엇입니까? 문제의 일부가 아닌 코드 (셀, 매개 변수, 시간, FontFactory 등)를 제거하여 위의 내용을 업데이트하십시오. 또한 데이터베이스가 없으므로 배열 배열처럼 재현 가능한 것을 제공하면 도움이됩니다. –

+0

SQL 연결 cn19와 SqlDataReader rdr11을 종료하지 않습니다. 또한 두 쿼리는 조건에 차이가 있습니다. 그게 유효합니까? – ray

+0

양자 택일로 당신은 당신의 문제를 이해할 수 있도록 http://sqlfiddle.com/을 만들 수 있습니다 –

답변

1

문제 : 아래 쿼리는 7 열을 얻을 것이다,하지 8. 그래서 ArgumentOutOfRangeException가 발생합니다.

select * from 
(select p1.PubID,p2.Publisher,p2.Title,p.name as authors 
from Personal_det p,Publication_Tracker p1,Publication_det p2 
where p.FID=p1.FID and p1.Contribution_Type='A' and p1.PubID=p2.PubID ) t1 
inner join 
    (select p.Name as coauthors,p2.PubID,p2.Type,p2.Title,p2.PubDate 
    from Personal_det p,Publication_Tracker p1,Publication_det p2 
    where p.FID=p1.FID and p1.Contribution_Type='C' and p1.PubID=p2.PubID ) t2 
    on t1.PubID = t2.PubID 

답 :

select * from 
(select p1.PubID,p2.Publisher,p2.Title as firsttitle,p.name as authors 
from Personal_det p,Publication_Tracker p1,Publication_det p2 
where p.FID=p1.FID and p1.Contribution_Type='A' and p1.PubID=p2.PubID ) t1 
inner join 
    (select p.Name as coauthors,p2.PubID,p2.Type,p2.Title,p2.PubDate 
    from Personal_det p,Publication_Tracker p1,Publication_det p2 
    where p.FID=p1.FID and p1.Contribution_Type='C' and p1.PubID=p2.PubID ) t2 
    on t1.PubID = t2.PubID