1. 程式人生 > >RDLC報表顯示存儲於數據庫的圖片

RDLC報表顯示存儲於數據庫的圖片

oca turn 獲取數據 hide exec 進制 () ram mage

圖片以二進制存儲於數據庫表中。在顯示RDLC報表時,把圖片呈現出來。

好吧。

把存儲過程寫好:
技術分享

技術分享
CREATE PROCEDURE [dbo].[usp_File_Select]
AS
SELECT [Afd_nbr],[Picture],[PictureType],[FileExtension] FROM [dbo].[ApiFileDemo]
GO
Source Code

在網站中,創建一個實體,是程序從數據庫獲取數據:
技術分享

技術分享
 public DataTable GetFiles()
        {
            sp.ConnectionString 
= DB.SqlConnectionString(); sp.Parameters = null; sp.ProcedureName = "usp_File_Select"; return sp.ExecuteDataSet().Tables[0]; }
Source Code



為站點添加一個rdlc報表,參考下面步驟:
技術分享


細節如下:
在報表視圖中,添加Table:
技術分享

技術分享

為表格選擇數據字段:
技術分享

報表設計完成。現在創建一個ASPX網頁來呈現這個RDLC報表:
技術分享

緊跟下來,是在ASPX.cs寫程序:

技術分享

技術分享
 private void Data_Binding()
    {
        this.ReportViewer1.Reset();
        this.ReportViewer1.LocalReport.Dispose();
        this.ReportViewer1.LocalReport.DataSources.Clear();

        Microsoft.Reporting.WebForms.ReportDataSource rds = new Microsoft.Reporting.WebForms.ReportDataSource();
        rds.Name 
= "FileDataSet"; FileEntity fe = new FileEntity(); rds.Value = fe.GetFiles(); this.ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Rdlc/ImageRpt.rdlc"); this.ReportViewer1.LocalReport.DataSources.Add(rds); this.ReportViewer1.LocalReport.Refresh(); }
Source Code

預覽一下看看結果如何:

技術分享


數據沒有顯示出來,一直不停在Loading...

看來我們寫少了程序,Insus.NET修改一下吧:
技術分享


哈,哈,顯示出來了:
技術分享

雖然數據顯示出來,但是在第二列中,圖片沒有顯示,卻顯示#Error。還沒有成功,還得繼續努力:
技術分享


最後看到想要的結果,圖片顯示出來了:
技術分享

RDLC報表顯示存儲於數據庫的圖片