2012-03-22 27 views
1

我不知道如何顯示「DVDImage」列中的圖像。報告工作正常,它的圖像不會出現。我必須將圖像轉換爲字節嗎?轉換爲字節後,如何將它放入列表視圖?圖像將不會出現在水晶報告

這裏是我的代碼:

 public void PrintDVDList(frmReportDVDList frmReportDVDList) 
     { 
      con.Open(); 

      DataTable dt = new DataTable(); 
      DataSet ds = new DataSet(); 
      ds.Tables.Add(dt); 
      OleDbDataAdapter da = new OleDbDataAdapter("SELECT ItemCode, Title, Genre, Film, YearReleased, Classification, NumberOfDiscs, DVDImage FROM tblDVDInventory ORDER BY Title", con); 
      da.Fill(dt); 

      ListView LV = new ListView(); 

      if (dt.Rows.Count > 0) 
      { 
       for (int ctr = 0; ctr <= dt.Rows.Count - 1; ctr++) 
       { 
        ListViewItem Item = new ListViewItem(); 
        Item.Text = dt.Rows[ctr]["ItemCode"].ToString(); 
        Item.SubItems.Add(dt.Rows[ctr]["Title"].ToString()); 
        Item.SubItems.Add(dt.Rows[ctr]["Genre"].ToString()); 
        Item.SubItems.Add(dt.Rows[ctr]["Film"].ToString()); 
        Item.SubItems.Add(dt.Rows[ctr]["YearReleased"].ToString()); 
        Item.SubItems.Add(dt.Rows[ctr]["Classification"].ToString()); 
        Item.SubItems.Add(dt.Rows[ctr]["NumberOfDiscs"].ToString()); 
        Item.SubItems.Add(dt.Rows[ctr]["DVDImage"].ToString()); 
        LV.Items.Add(Item); 
       } 
      } 

      con.Close(); 

      rptDVDList Report = new rptDVDList(); 

      Report.SetDataSource(ds.Tables[0]); 
      frmReportDVDList.crvDVDList.ReportSource = Report; 
      frmReportDVDList.crvDVDList.Refresh(); 
     } 
+1

你能解釋一下listview的用途嗎?你能否直接從數據庫填充報告而不是使用中間數據集? – 2012-03-22 13:25:24

+0

除了Lee寫的:這裏有很多代碼,你並不需要('if'和DataSet) – Carsten 2012-03-22 13:29:04

+0

是的,但我可以在CR中遇到問題,當我直接從數據庫使用報表時,它會在我運行到另一個PC終端時提示密碼。這就是我使用中間數據集的原因。 – 2012-03-22 13:29:48

回答

0

這是示例代碼中,我通常建議看在C#中開始使用Crystal Reports時,在:

using System; 
using System.Windows.Forms; 
using CrystalDecisions.CrystalReports.Engine; 
using CrystalDecisions.Shared; 

namespace WindowsApplication1 
{ 
    public partial class Form1 : Form 
    { 
     public Form1() 
     { 
      InitializeComponent(); 
     } 

     private void button1_Click(object sender, EventArgs e) 
     { 
      ReportDocument cryRpt = new ReportDocument(); 
      TableLogOnInfos crtableLogoninfos = new TableLogOnInfos(); 
      TableLogOnInfo crtableLogoninfo = new TableLogOnInfo(); 
      ConnectionInfo crConnectionInfo = new ConnectionInfo(); 
      Tables CrTables ; 

      cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt"); 

      crConnectionInfo.ServerName = "YOUR SERVER NAME"; 
      crConnectionInfo.DatabaseName = "YOUR DATABASE NAME"; 
      crConnectionInfo.UserID = "YOUR DATABASE USERNAME"; 
      crConnectionInfo.Password = "YOUR DATABASE PASSWORD"; 

      CrTables = cryRpt.Database.Tables ; 
      foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables) 
      { 
       crtableLogoninfo = CrTable.LogOnInfo; 
       crtableLogoninfo.ConnectionInfo = crConnectionInfo; 
       CrTable.ApplyLogOnInfo(crtableLogoninfo); 
      } 

      crystalReportViewer1.ReportSource = cryRpt; 
      crystalReportViewer1.Refresh(); 
     } 
    } 
} 

來源:http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-dynamic-login.htm

你可以通過在代碼中傳遞連接信息來查看,用戶不會被提示。沒有必要使用中間數據集。