2

Hello I have got this line of code to load the image from Sql Database:

MemoryStream mem;
    void zobraz_logo()
    {
        try
        {
            SqlDataAdapter dataAdapter = new SqlDataAdapter(new SqlCommand("SELECT logo FROM firma WHERE id = 1", spojeni));
            DataSet dataSet = new DataSet();


            dataAdapter.Fill(dataSet);


            if (dataSet.Tables[0].Rows.Count == 1)
            {
                Byte[] data = new Byte[0];
                data = (Byte[])(dataSet.Tables[0].Rows[0]["logo"]);
                 mem = new MemoryStream(data);

            }

        }

        catch (Exception)
        {
            MessageBox.Show("");
        }

    }

Now I'm trying to pass it as parameter to ReportViewer:

eportParameter[] parameter = new ReportParameter[18];

            parameter[18] = new ReportParameter("rp_logo", Image.FromStream(mem)); // this is the issue line


            this.firmaTableAdapter.Fill(this.dataset_voucher.firma);
            this.zajezdTableAdapter.Fill(this.dataset_voucher.zajezd,vybrana_akce,klientClass.Rocnik());


            this.reportViewer1.LocalReport.SetParameters(parameter);
            this.reportViewer1.RefreshReport();


        }

I'm trying to load image as parameter to Image of the ReportViewer I hope it is possible do it this way. If not May you please propose me the best way to do that?

On the mentioned line I'm receiving error: Argument 2:cannot convert from System.Drawing.Image to String[]

Thank you for your time.

4

2 回答 2

2

我从未使用过报表查看器,但在 Crystal 报表中,您将参数/字段创建为对象类型,并将 a 传递byte[]给该参数/字段。

于 2013-09-09T13:17:09.780 回答
1

好吧,正如您在MSDNReportParameter中看到的那样,您可以看到接受字符串、字符串数组和布尔值。

你应该使用其中之一。

我不知道图片的用途,但您可以在报告中使用它的路径

parameter[18] = new ReportParameter("rp_logo", new string[]{dataImage});
于 2013-09-09T13:13:12.193 回答