如何使用asp.net,我的sql在水晶报表中存储图像和显示图像 [英] How to store images and displaying images in crystal reports using asp.net,my sql

查看:53
本文介绍了如何使用asp.net,我的sql在水晶报表中存储图像和显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

我正在开发一个网站。这里将图像保存到数据库/文件夹中,并在水晶报告中显示图像以供打印。哪一种更好地将图像(二进制/任何格式)存储到数据库/文件夹中以及如何在水晶报告中显示图像。

谢谢你。

解决方案

嗨...

最后我找到了保存和解决方案使用mysql,asp.net从数据库在水晶报表中显示图像!



我的 数据库表

ImgId Int;

Image Blob;

ImgLength int;

ImgName varchar;

ImgPath varchar;



准备 数据集(xsd) 如:

图像字节[];

长度int;

ImgName字符串;

ImgPath字符串;



aspx.cs :以二进制格式保存

  protected   void  btn_saveimg_Click( object  sender,EventArgs e)
{
// 将img转换为二进制
Stream fs = ImgFileUpload.PostedFile.InputStream;
int imglength = ImgFileUpload.PostedFile.ContentLength;
byte [] imgbytes = new byte < /跨度> [imglength];
// 保存img位置
string imgname = Path.GetFileName(ImgFileUpload.PostedFile.FileName);
ImgFileUpload.SaveAs(Server.MapPath( 〜/ PhotosGallery / + imgname)) ;
string imgpath = 〜/ PhotosGallery / + imgname;

con = new MySqlConnection(cs);
con.Open();
cmd = new MySqlCommand( insert into binaryimageformat(image,length,imgname,imgpath)values(' + imgbytes + ',' + imglength + ',' + imgname + ',' + imgpath + '),con);
cmd.ExecuteNonQuery();
con.Close();

lblimg.Text = 以二进制格式保存的图像;
}





aspx.cs :检索binaryimg到crystalreports

  protected   void  btn_viewreport_Click(  object  sender,EventArgs e)
{
con = new MySqlConnection(cs) ;
cmd = new MySqlCommand( select *来自binaryimageformat,con);
con.Open();
cmd.ExecuteNonQuery();
da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();

for int index = 0 ; index < ds.Tables [ 0 ]。Rows.Count; index ++ )
{
if (ds.Tables [ 0 ]。行[index ] [ ImgPath]。ToString()!=
{
string s = this .Server.MapPath(ds.Tables [ 0 ]。行[index] [ ImgPath]。ToString());

if (File.Exists(s))
{
LoadImage(ds.Tables [ 0 ]。行[index], 图像,或多个);
}
else
{
LoadImage(ds.Tables [ 0 ]。行[index], 图像 〜/ PhotosGallery / No Image.jpg);
}
}
else
{
LoadImage(ds.Tables [ 0 ]。行[index], 图像 〜/ PhotosGallery / No Image.jpg);
}
}

ReportDocument crDoc = new ReportDocument();
crDoc.Load(Server.MapPath( CrystalReport.rpt));
crDoc.SetDataSource(ds.Tables [ 0 ]);
CrystalReportViewer1.ReportSource = crDoc;
}

private void LoadImage(DataRow objDataRow, string strImageField, string FilePath)
{
尝试
{
FileStream fs = new FileStream(FilePath,System.IO.FileMode.Open,System.IO.FileAccess 。读);
byte [] Image = new byte [fs.Length];
fs.Read(Image, 0 ,Convert.ToInt32(fs.Length));
fs.Close();
objDataRow [strImageField] =图片;
}
catch (例外情况)
{
Response.Write( < font color = red > + ex.Message + < / font>) ;
}
}





感谢您的支持。


< blockquote class =FQ>

引用:

如何使用asp.net存储图像并在水晶报表中显示图像



参见此处:

http://www.aspdotnet- suresh.com/2012/02/dynamically-display-images-in-crystal.html [ ^ ]

引用:

哪一个更好地将图像(二进制/任何格式)存储到数据库/文件夹中



请参阅:

http://stackoverflow.com/questions/522957/what -is最最好的格式到存储图像-IN-A-数据库 [<一个href =http://stackoverflow.com/questions/522957/what-is-the-best-format-to-store-images-in-a-databasetarget =_ blanktitle =New Window> ^ ]



除上述链接外,请在此处查看一些不错的解决方案:

http://blogs.msdn.com/b/brian_swan /archive/2010/03/25/store-images-in-the-database-or-file-system.aspx [ ^ ]

http://www.sourcecodester.com/ article / other / should-i-save-images-database-or-file-system.html [ ^ ]

http://stackoverflow.com/questions/561447/store -pictures-as-files-or-the-database-for-a-web-app [ ^ ]


Hi...
I am developing a website. Here am saving images into database/folder and displaying images in crystal reports for printing purpose. Which one is better to store images(in binary/any formats) in to database/folder and how to display images in crystal reports.
thank u.

解决方案

Hi...
Finally i found the solution for saving & displaying images in crystal reports from database using mysql,asp.net!

My database table:
ImgId Int;
Image Blob;
ImgLength int;
ImgName varchar;
ImgPath varchar;
and
prepare dataset(xsd) like:
Image byte[];
Length int;
ImgName string;
ImgPath string;

In aspx.cs: to save in binary format

protected void btn_saveimg_Click(object sender, EventArgs e)
    {
        //convert img to binary
        Stream fs = ImgFileUpload.PostedFile.InputStream;
        int imglength = ImgFileUpload.PostedFile.ContentLength;
        byte[] imgbytes = new byte[imglength];
        //saving img location
        string imgname = Path.GetFileName(ImgFileUpload.PostedFile.FileName);
        ImgFileUpload.SaveAs(Server.MapPath("~/PhotosGallery/" + imgname));
        string imgpath = "~/PhotosGallery/" + imgname;

        con = new MySqlConnection(cs);
        con.Open();
        cmd = new MySqlCommand("insert into binaryimageformat(image,length,imgname,imgpath) values('"+ imgbytes +"','"+ imglength +"','"+ imgname +"','"+ imgpath +"')", con);
        cmd.ExecuteNonQuery();
        con.Close();

        lblimg.Text = "Image saved in binary format";
    }



in aspx.cs: to retrieving binaryimg to crystalreports

protected void btn_viewreport_Click(object sender, EventArgs e)
    {
        con = new MySqlConnection(cs);        
        cmd = new MySqlCommand("select * from binaryimageformat", con);
        con.Open();
        cmd.ExecuteNonQuery();
        da = new MySqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);        
        con.Close();

        for (int index = 0; index < ds.Tables[0].Rows.Count; index++)
        {
            if (ds.Tables[0].Rows[index]["ImgPath"].ToString() != "")
            {
                string s = this.Server.MapPath(ds.Tables[0].Rows[index]["ImgPath"].ToString());

                if (File.Exists(s))
                {
                    LoadImage(ds.Tables[0].Rows[index], "Image", s);
                }
                else
                {
                    LoadImage(ds.Tables[0].Rows[index], "Image", "~/PhotosGallery/No Image.jpg");
                }
            }
            else
            {
                LoadImage(ds.Tables[0].Rows[index], "Image", "~/PhotosGallery/No Image.jpg");
            }
        }

        ReportDocument crDoc = new ReportDocument();
        crDoc.Load(Server.MapPath("CrystalReport.rpt"));
        crDoc.SetDataSource(ds.Tables[0]);
        CrystalReportViewer1.ReportSource = crDoc;
    }

private void LoadImage(DataRow objDataRow, string strImageField, string FilePath)
    {
        try
        {
            FileStream fs = new FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            byte[] Image = new byte[fs.Length];
            fs.Read(Image, 0, Convert.ToInt32(fs.Length));
            fs.Close();
            objDataRow[strImageField] = Image;
        }
        catch (Exception ex)
        {
            Response.Write("<font color="red">" + ex.Message + "</font>");
        }
    }



Thanks for ur's supports.


Quote:

How to store images and displaying images in crystal reports using asp.net


Refer here:
http://www.aspdotnet-suresh.com/2012/02/dynamically-display-images-in-crystal.html[^]

Quote:

Which one is better to store images(in binary/any formats) in to database/folder


See this :
http://stackoverflow.com/questions/522957/what-is-the-best-format-to-store-images-in-a-database[^]

In addition to above links please see some good solutions here:
http://blogs.msdn.com/b/brian_swan/archive/2010/03/25/store-images-in-the-database-or-file-system.aspx[^]
http://www.sourcecodester.com/article/other/should-i-save-images-database-or-file-system.html[^]
http://stackoverflow.com/questions/561447/store-pictures-as-files-or-in-the-database-for-a-web-app[^]


这篇关于如何使用asp.net,我的sql在水晶报表中存储图像和显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆