2012-04-10 94 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. 鏈接此爲您鏈接簡單顯示其他記錄。

我已經在我的項目進行了測試