2012-04-10 89 views
0

我使用VS 2008和水晶报表版本显示JPG图像10.5(我保存在SQL数据库图像路径)如何使用CR 10.5与Visual Studio 2008

我希望把动态图像 我该怎么办 请帮助我。

+0

[你尝试过什么?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) – user850498 2012-04-10 08:17:49

回答

0

您可以参考this 或按照步骤

- >当数据库文件路径店,需要显示在水晶报表

的细节部分的图像如果您有存储在ImagePath的你数据库,Visual Studio 2003/2005中的Crystal Report .NET无法动态显示图像文件,除非您在Crystal Report XI中使用动态图像位置功能。

但不要担心,它可以显示一些解决此问题的方法。

  1. 您的数据库中必须有图像路径。

  2. 创建新的数据集/ XML模式(xsd)以用作创建报告中的资源数据。添加附加字段,是不是在桌子这是base64Binary类型的:

  3. 设计报表时的阻力,并在您希望它出现的区域去掉“image_stream”字段。

  4. 在你的代码添加下面的方法:

    私人无效AddImageColumn(数据表objDataTable,串strFieldName) { 尝试 { 的DataColumn objDataColumn =新的DataColumn(strFieldName,Type.GetType(“System.Byte []“)); objDataTable.Columns.Add(objDataColumn); } catch(Exception ex) Response.Write(“”+ ex.Message +“”); } }

  5. 而这一次加载图像:

    私人无效的LoadImage(DataRow的objDataRow,串strImageField,字符串文件路径) { 尝试 { 的FileStream FS =新的FileStream(文件路径,系统.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] =图像; } catch(Exception ex) Response.Write(“”+ ex.Message +“”); }}

  6. 之前分配数据集到您的报告“的setDataSource”,添加以下代码:

    AddImageColumn(ds.Tables [0],“image_stream”); for(int index = 0; index < ds.Tables [0] .Rows。计数;索引++) if(ds.Tables [0] .Rows [index] [“image_path”] .ToString()!=“”) if(File.Exists(this.Server.MapPath(ds.Tables [0] .Rows [index] [“image_path”]。ToString()))) LoadImage(ds.Tables [0] .Rows [index],“image_stream”,ds.Tables [0] .Rows [指数] [ “IMAGE_PATH”]的ToString()); LoadImage(ds.Tables [0] .Rows [index],“image_stream”,“C:\ NoImage.jpg”); LoadImage(ds.Tables [0] .Rows [index],“image_stream”,“C:\ NoImage.jpg”);}} } }

  7. 最后,在晶体报告查看器中显示报告

    crDoc.SetDatabaseLogon(用户ID,密码,服务器,数据库); crDoc.SetDataSource(ds.Tables [0]); CrystalReportViewer1.ReportSource = crDoc;

未测试。

+0

谢谢非常。我做不到。请告诉我我做了什么? – 2012-04-11 07:32:09

0

它实际上是容易的,按照这个镫:除非你已经在使用OLE

  1. ,创建表的数据库字段的新连接crystareport1
  2. 选择OLE DB(ADO)
  3. 添加表图像存储在哪里。
  4. 提供系统所需的数据库信息
  5. 现在您已将数据表添加到数据库字段中。
  6. 只需将图像拖放到section3区域即可。
  7. 链接此为您链接简单显示其他记录。

我已经在我的项目进行了测试