VS2005下水晶报表中如何读取数据中存储的图片显示出来 比如我现在有一表:TB有字段:Name,Sex,Age,Photo其中Photo字段为Image类型现在我建了一个rpt,用crystalreportview显示报表问:如何将Photo在报表中显示出来,高手请帮忙,谢谢~~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Response.BinaryWrite((byte[])nw.Photo);但是我不会在image控件中显示。不知道有人会吗? 请楼上的指点一下。如果用Response.BinaryWrite就会在一个新的页面中打开。如果在控件中同一页面中打开,应该如何操作。 在WINFORM下CryStalReport显示图片哟哪里有资料,请大虾共享一下,谢谢了! 把图片写入SQL数据库,在程序中建一个数据集,把这张表加入数据集,直接把这个图片字段拖到报表上面就可以显示了,不需做任何动作如果想显示不同图片,这个数据表中图片字段不要赋值,让他空着加载到dataset中,然后在程序某个按钮事件中:byte[] bys = cardWeb.DownloadPhoto(strcardid, strunitid);FileStream fs = new FileStream(@"D:\image\财务部.jpg", FileMode.OpenOrCreate, FileAccess.Read);bys = new byte[fs.Length];fs.Read(bys, 0, System.Convert.ToInt32(fs.Length));fs.Close();ds.Tables["Chk_CardTitle"].Rows[0]["Img"] = bys;crystalreportview.RefreshReport();这样就可以显示不同的图片了 byte[] bys = cardWeb.DownloadPhoto(strcardid, strunitid);这句改一下,那事我吊的别的方法,^_^ 兄弟,我按照那样的方法得不到图片呀,结果显示为“System.Byte []”代码:byte[] mydata = ((byte[])ds.Tables[0].Rows[0]["ImgData"]);FileInfo fi = new FileInfo("temp");FileStream fs = fi.Open(FileMode.Create);mydata = new byte[fs.Length];fs.Read(mydata, 0, System.Convert.ToInt32(fs.Length));fs.Close();card.Tables[0].Rows[0]["Photo"] = mydata;CardRpt rpt = new CardRpt();rpt.SetDataSource(card.Tables[0]);crystalReportViewer1.ReportSource = rpt;其中card是一个数据集,ds.Tables[0].Rows[0]["ImgData"])是从数据库中读取存储的图片字段这样写有问题吗,请指正,谢谢~~ byte[] mydata = ((byte[])ds.Tables[0].Rows[0]["ImgData"]);改为byte[] mydata;这是换不同的图;若不换,不要写代码,直接拖Photo进RPT就行了 CrystalReport本身就支持image类型的显示 老兄看下面的两个贴子:http://blog.csdn.net/haibodotnet/archive/2004/04/12/21570.aspxhttp://www.cnblogs.com/oosnoopy/archive/2005/12/17/299022.html 用一个空白网页,cs文件或其他的都可以(只是使用时有细微的区别),网页(其他一样)完成的唯一功能就是Response.BinaryWrite((byte[])nw.Photo);然后用image控件定位到这个网页(其他一样),或用IMG定位到这个网页(其他一样)就可以了 这个可以。。我实现了 public static byte[] GetPhoto(string filePath) //函数 { FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); byte[] photo = br.ReadBytes((int)fs.Length); br.Close(); fs.Close(); return photo; } public void seephoto() //读取 SQL图片 { try { string ConnectionString ="server=.;uid=sa;pwd=;database=system"; SqlConnection conn=new SqlConnection(ConnectionString); string sql="select Student_Photo from Student_Table where Student_Bianhao='"+this.label16.Text+"'"; SqlCommand command = new SqlCommand(sql,conn); conn.Open(); SqlDataReader dr = command.ExecuteReader(CommandBehavior.SequentialAccess); if(dr.Read()) { MemoryStream ms = new MemoryStream(((byte[])dr["Student_Photo"])); this.pictureBox1.Image = Image.FromStream(ms,true); } else { MessageBox.Show("没有成功读入数据!") ; } conn.Close(); } catch(Exception x) { MessageBox.Show(x.Message); } } 关于控件外观的问题 如何判断子窗体是否加载完成 如何将datatable中的rows随机划分 一个事件的小问题 XmlNode 中如何给节点添加一个兄弟节点 关于 statusstrip 控件右下角小手柄,SizingGrip=false 但那一小正方块仍存在,向高手们求救~!~!~! 关于SOAP访问WebService的问题? 求教:如何最快的求出两个数组的交集? C#的注释中,可以用几种着色来注释吗,这样可以让我明白注释的不同重要性 请问:C#大虾 怎样取得某个Class自身的实例名称? 大家帮忙看看
但是我不会在image控件中显示。不知道有人会吗?
如果用Response.BinaryWrite就会在一个新的页面中打开。如果在控件中同一页面中打开,应该如何操作。
哪里有资料,请大虾共享一下,谢谢了!
如果想显示不同图片,这个数据表中图片字段不要赋值,让他空着加载到dataset中,然后在程序某个按钮事件中:
byte[] bys = cardWeb.DownloadPhoto(strcardid, strunitid);
FileStream fs = new FileStream(@"D:\image\财务部.jpg", FileMode.OpenOrCreate, FileAccess.Read);
bys = new byte[fs.Length];
fs.Read(bys, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
ds.Tables["Chk_CardTitle"].Rows[0]["Img"] = bys;
crystalreportview.RefreshReport();
这样就可以显示不同的图片了
这句改一下,那事我吊的别的方法,^_^
代码:
byte[] mydata = ((byte[])ds.Tables[0].Rows[0]["ImgData"]);
FileInfo fi = new FileInfo("temp");
FileStream fs = fi.Open(FileMode.Create);
mydata = new byte[fs.Length];
fs.Read(mydata, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
card.Tables[0].Rows[0]["Photo"] = mydata;CardRpt rpt = new CardRpt();
rpt.SetDataSource(card.Tables[0]);
crystalReportViewer1.ReportSource = rpt;其中card是一个数据集,ds.Tables[0].Rows[0]["ImgData"])是从数据库中读取存储的图片字段
这样写有问题吗,请指正,谢谢~~
改为byte[] mydata;
这是换不同的图;
若不换,不要写代码,直接拖Photo进RPT就行了
http://blog.csdn.net/haibodotnet/archive/2004/04/12/21570.aspxhttp://www.cnblogs.com/oosnoopy/archive/2005/12/17/299022.html
然后用image控件定位到这个网页(其他一样),或用IMG定位到这个网页(其他一样)就可以了
public static byte[] GetPhoto(string filePath) //函数
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] photo = br.ReadBytes((int)fs.Length);
br.Close();
fs.Close();
return photo;
} public void seephoto() //读取 SQL图片
{
try
{
string ConnectionString ="server=.;uid=sa;pwd=;database=system";
SqlConnection conn=new SqlConnection(ConnectionString);
string sql="select Student_Photo from Student_Table where Student_Bianhao='"+this.label16.Text+"'";
SqlCommand command = new SqlCommand(sql,conn);
conn.Open();
SqlDataReader dr = command.ExecuteReader(CommandBehavior.SequentialAccess);
if(dr.Read())
{
MemoryStream ms = new MemoryStream(((byte[])dr["Student_Photo"]));
this.pictureBox1.Image = Image.FromStream(ms,true);
}
else
{
MessageBox.Show("没有成功读入数据!") ;
}
conn.Close();
}
catch(Exception x)
{
MessageBox.Show(x.Message);
}
}