![](/img/trans.png)
[英]How to display image in RDLC report from when only image name saved in database?
[英]How to display image from database on RDLC report
我的 RDLC 設計:
我想在我的數據庫中的報告查看器上顯示圖像我的報告查看器工作正常我只需要每個選擇的圖像,並且我的數據庫中已經有每個患者的圖像我只想在我的 .aspx 頁面中顯示該圖像我也附上下面的代碼。
我的 Aspx 頁面:
<body >
<form id="form1" runat="server">
<div class="auto-style1">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table class="auto-style2">
<tr>
<td class="auto-style5">
<asp:Label ID="Label1" runat="server" CssClass="auto-style4"
Text="Patient Report"></asp:Label>
<asp:DropDownList ID="DropDownPat" runat="server" Height="16px"
Width="157px" AutoPostBack="True"
OnSelectedIndexChanged="DropDownPat_SelectedIndexChanged">
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</tr>
<tr>
<td class="auto-style3">
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" Height="205px" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Width="751px">
<LocalReport ReportPath="Report1.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
</DataSources>
</LocalReport>
</rsweb:ReportViewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="MedImage.DataSet1TableAdapters.DataTable1TableAdapter"></asp:ObjectDataSource>
</td>
</tr>
</table>
</div>
</form>
</body>
我的 .cs 文件:我想在我的數據庫中的報告查看器上顯示圖像
aspx 頁面背后的代碼在這里
public partial class PatientReport : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
populateDropDownPat();
}
}
private void populateDropDownPat()
{
try
{
patientCollection pcal = (new patientBAL()).GetAllDetailspatient();
DropDownPat.DataSource = null;
DropDownPat.DataSource = pcal;
DropDownPat.DataTextField = "patientName";
DropDownPat.DataValueField = "PatientID";
DropDownPat.DataBind();
DropDownPat.Items.Insert(0, new ListItem("--Select Patient--"));
}
catch(Exception ex)
{
}
}
protected void DropDownPat_SelectedIndexChanged(object sender, EventArgs e)
{
string name = DropDownPat.SelectedItem.Text;
patientCollection pcal = (new
patientBAL()).GetDetailsByPatientName(name);
ReportViewer1.Visible = true;
this.ReportViewer1.LocalReport.EnableExternalImages = true;
this.ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";
ReportViewer1.LocalReport.DataSources.Clear();
ReportDataSource rds = new ReportDataSource("DataSet1", pcal);
this.ReportViewer1.LocalReport.DataSources.Add(rds);
this.ReportViewer1.LocalReport.Refresh();
}
}
用於存儲Image
數據類型:
varbinary(MAX)
byte[] bytes;
using (BinaryReader br = new BinaryReader(photo.PostedFile.InputStream))
{
bytes = br.ReadBytes(photo.PostedFile.ContentLength);
}
SqlCommand cmd = new SqlCommand("insert into img values('@harikesh')", cn);
cn.Open();
cmd.Parameters.AddWithValue("@harikesh", bytes);
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script language='javascript'>alert('inserted sucess')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('NOT sucess')</script>");
}
cn.Close();`
------------- 在報告視圖上查看圖像-------------
.xsd 文件System.Byte[]
圖像數據類型
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.