图像不会出现在水晶报告中

时间:2012-03-22 13:20:03

标签: c# crystal-reports

我想知道如何在“DVDImage”列中显示图像。该报告工作正常,只是图像不会出现。我必须将图像转换为字节吗?如何在转换为字节后将其放入listview?

这是我的代码:

        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 个答案:

答案 0 :(得分: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

您可以通过在代码中传递连接信息来查看,不会提示用户。无需使用中间数据集。