日期:2014-05-20  浏览次数:20866 次

VS2005下水晶报表中如何读取数据中存储的图片显示出来
比如我现在有一表:TB
有字段:Name,Sex,Age,Photo
其中Photo字段为Image类型

现在我建了一个rpt,用crystalreportview显示报表
问:如何将Photo在报表中显示出来,高手请帮忙,谢谢~~

------解决方案--------------------
帮顶,我也想知道
------解决方案--------------------
Response.BinaryWrite((byte[])nw.Photo);
但是我不会在image控件中显示。不知道有人会吗?
------解决方案--------------------
网上大把的资料
------解决方案--------------------
请楼上的指点一下。
如果用Response.BinaryWrite就会在一个新的页面中打开。如果在控件中同一页面中打开,应该如何操作。
------解决方案--------------------
把图片写入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);
这句改一下,那事我吊的别的方法,^_^
------解决方案--------------------
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.aspx

http://www.cnblogs.com/oosnoopy/archive/2005/12/17/299022.html
------解决方案--------------------
这个可以。。我实现了
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);
}
}
------解决方案--------------------
2005不清楚,在2003 + CR10里跟别的字段一样,直接拖进去就可以显示了
------解决方案--------------------
up