Click here to Skip to main content
15,896,502 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
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

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:

VB
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:
VB
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.
 
Share this answer
 
Comments
Shanmugam Vasu 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?
Shanmugam Vasu 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?
Shanmugam Vasu 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.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900