Click here to Skip to main content
12,629,107 members (35,270 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB Visual-Studio VB.NET , +
I am having the path of the picture in database.
Now I want to display images in crystalreport

I have a Dataset namely, "Details" which includes an additional field(not in table of db) namely "Image(Byte)"

And I read all my path of pictures and fill into dataset.
After that, I am doing the following for displaying the image.
But it doesn't work.

For i = 0 To ds.Tables("Details").Rows.Count - 1 Step 1
     cmdstr = ds.Tables("Details").Rows(i)("Path").ToString
     Dim fs As New FileStream(cmdstr, FileMode.Open, FileAccess.Read)
     Dim om As Byte() = New Byte(fs.Length) {}
     fs.Read(om, 0, Convert.ToInt32(fs.Length))
     ds.Tables("Details").Rows(i)("Image") = om
Next

Error is : Column image does not belongs to datatable.

Can any one tell me where I was wrong ?

Thanks
Posted 9-Aug-12 1:47am
v2
Comments
dimpledevani 9-Aug-12 8:41am
   
It means that your datatable does not have any column named 'Image' ,Check you column names

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It sounds like you don't really have a column named Image in the dataTable named Details. Can you post the code that you use to create and add that column? I'm guessing it should look something like this:

ds.Tables("Details").Columns.Add("Image", System.Type.GetType("System.Byte[]"))

Also, just as a side note, I noticed that you are not using a For Each loop which would make your code a lot cleaner and is very nice and easy to use. Instead of doing a regular For Loop where you have to specify an integer to increment and step, etc. You can use a For Each and it knows to just iterate through a collection. Here is a link that explains it:
For Each...Next Statement[^]

Also, there is a quicker way to grab all of the bytes in a file. You can use System.IO.File.ReadAllBytes(strFilePath).

So once you get your column properly added to the DataTable in your DataSet, you could simplifiy your loop code to this:
For Each row As DataRow In ds.Tables("Details").Rows
    If System.IO.File.Exists(row("Path").ToString) Then
        row("Image") = System.IO.File.ReadAllBytes(row("Path").ToString)
    End If
Next

Hope this helps.
  Permalink  
Comments
shanmugamvasu 10-Aug-12 1:29am
   
Thanks for your reply

i was tried your code, but i am unable to get the images in report.

I have a Dataset Namely "Dataset1" with One DataTable Namely "Details"

This Details Datatable has two Columns

Path system.String

Image system.byte

based on this dataset i was created my report.

This is my code:

ds = New DataSet1()
Dim t As DataTable = ds.Tables.Add("DT_Details")
t.Columns.Add("Path", System.Type.GetType("System.String"))
t.Columns.Add("Image", System.Type.GetType("System.Byte[]"))
imgpath = "E:\My Documents\Desk\canstock5872904.jpg"
Dim row As DataRow
row = t.NewRow()
row("Path") = imgpath
row("Image") = System.IO.File.ReadAllBytes(imgpath)
t.Rows.Add(row)
cryRpt = New CrystalReport1()
path = Application.StartupPath & "\" & "CrystalReport1.rpt"
cryRpt.Load(path)
cryRpt.SetDataSource(ds.Tables(1))
CrystalReportViewer1.ReportSource = cryRpt
CrystalReportViewer1.Refresh()

Please Guide me.
Kschuler 13-Aug-12 9:06am
   
Are you still getting the same error about the Image Column not being in the table? And if so, which line of code exactly is it blowing up on?
shanmugamvasu 13-Aug-12 9:16am
   
No there was no error in the code .. But image was not display in report. I am using Crystal Report for Visual Studio 2005. Is Version of Crystal Report a Problem?
Kschuler 13-Aug-12 9:22am
   
How are you displaying it in your report? In reports that I have made, I drag and drop the image field onto the report and it creates an IBlobFieldObject. Do you have that? When you debug your code, can you see that the Image column is getting filled with data?
shanmugamvasu 14-Aug-12 1:08am
   
I was generate the report based on dataset (datatable-Details). This datatable has two columns (path[string],Image[Byte]). And i was searched about IBlodFieldObject but i am unable to get it. Please guide me how creates a IBlodFieldObject in report and how use this in code.
Kschuler 14-Aug-12 8:40am
   
The IBlobFieldObject is what appears in the design mode of the Crystal Report. You create it by dragging the Image[Byte] column from the list of fields onto the report in the location that you want it to appear. It's not something that you really deal with in the code. Have you designed your report to let it know where you want the fields to appear?
shanmugamvasu 15-Aug-12 1:55am
   
yes i was designed my report. The image column should display in the detail Section.
shanmugamvasu 30-Aug-12 0:30am
   
Finally i found my mistake .. I was missed the '()' Byte array notation in dataset column datatype. Now images displays in the Report .. Thanks for your valuable guidelines ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161205.3 | Last Updated 9 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100