首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在RDLC报表上显示数据库中的图像

问如何在RDLC报表上显示数据库中的图像
EN

Stack Overflow用户
提问于 2017-08-30 19:25:53
回答 2查看 9.1K关注 0票数 0

我的RDLC设计:

​

​

我想在我的报告查看器上显示来自我的数据库的图像,我的报告查看器工作得很好,我只需要为每个选择提供一个图像,并且我已经在我的数据库中为每个患者提供了图像,我只想显示在我的.aspx页面中,我还附加了下面的代码。

我的Aspx页面:

代码语言:javascript
复制
<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">  &nbsp;&nbsp;
             <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页面背后的代码在这里

代码语言:javascript
复制
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(); 
        }
    }
EN

回答 2

Stack Overflow用户

发布于 2017-08-31 14:31:58

显示数据库中的图像非常容易。在image属性上,将源设置为数据库,并将包含byte[]图像的值设置为dataset字段。

​

​

票数 0
EN

Stack Overflow用户

发布于 2018-10-18 14:42:11

用于存储Image的数据类型

代码语言:javascript
复制
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[]中的图像数据类型

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45959148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档