RDLC報表顯示存儲於數據庫的圖片
阿新 • • 發佈:2017-11-04
oca turn 獲取數據 hide exec 進制 () ram mage
圖片以二進制存儲於數據庫表中。在顯示RDLC報表時,把圖片呈現出來。
好吧。
把存儲過程寫好:
CREATE PROCEDURE [dbo].[usp_File_Select] AS SELECT [Afd_nbr],[Picture],[PictureType],[FileExtension] FROM [dbo].[ApiFileDemo] GOSource Code
在網站中,創建一個實體,是程序從數據庫獲取數據:
public DataTable GetFiles() { sp.ConnectionStringSource Code= DB.SqlConnectionString(); sp.Parameters = null; sp.ProcedureName = "usp_File_Select"; return sp.ExecuteDataSet().Tables[0]; }
為站點添加一個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.NameSource Code= "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(); }
預覽一下看看結果如何:
數據沒有顯示出來,一直不停在Loading...
看來我們寫少了程序,Insus.NET修改一下吧:
哈,哈,顯示出來了:
雖然數據顯示出來,但是在第二列中,圖片沒有顯示,卻顯示#Error。還沒有成功,還得繼續努力:
最後看到想要的結果,圖片顯示出來了:
RDLC報表顯示存儲於數據庫的圖片