jrandallsexton
asked on
Dynamic Content into Crystal Report
Hello:
Is there a way to put a "placeholder" (if you will) in CR, that would hold an image created during runtime by VB.Net.
In other words, a big empty spot in the CR designer, that would be filled by a picture that was created by VB.Net and inserted maybe via bitstream.
Please give me some ideas!!!
Thanks in advance.
Is there a way to put a "placeholder" (if you will) in CR, that would hold an image created during runtime by VB.Net.
In other words, a big empty spot in the CR designer, that would be filled by a picture that was created by VB.Net and inserted maybe via bitstream.
Please give me some ideas!!!
Thanks in advance.
ASKER
I don't have VB6 installed and the conversion wizard bombed.
I really need a .Net example.
Thanks!!!
I really need a .Net example.
Thanks!!!
ASKER
What about storing an image in SQL server, and simply pulling from image datatype into report? I tried it, but couldn't make it work. Anyone ever do that before?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ebolek:
I appreciate the link you posted. However, simply posting code doesn't always help.
What did you do? Did you create a strongly typed dataset and design the Crystal Report from the XML file you produced from the dataset?
Looks like your dataset is:
PicNumber Integer
ImagePath String
Image Byte[]
Is that correct?
How did you get Crystal to display an image instead of an empty blob field? I ask this because I tried something similar by storing images in SQL server using an Image datatype. I pointed the report to the table and when it came back, there were empty squares where the pictures should have been.
I appreciate the link you posted. However, simply posting code doesn't always help.
What did you do? Did you create a strongly typed dataset and design the Crystal Report from the XML file you produced from the dataset?
Looks like your dataset is:
PicNumber Integer
ImagePath String
Image Byte[]
Is that correct?
How did you get Crystal to display an image instead of an empty blob field? I ask this because I tried something similar by storing images in SQL server using an Image datatype. I pointed the report to the table and when it came back, there were empty squares where the pictures should have been.
ASKER
ebolek:
I got it working.
For everyone else: Execute your code so that the XML file creates, then base your report off of the XML file. When you go to run the report 'for real', simply use: myReport.SetDataSource(myD ataSet)
The VB.Net code is posted below:
************************** ********** ********** ********** *******
Dim myDataset As New DataSet
Dim myDataTable As DataTable
Dim myDataRow As DataRow
myDataTable = New DataTable
Dim myDataColumn As New DataColumn
myDataColumn = New DataColumn("PicNumber", Type.GetType("System.Int32 "))
myDataTable.Columns.Add(my DataColumn )
myDataColumn = New DataColumn("ImagePath", Type.GetType("System.Strin g"))
myDataTable.Columns.Add(my DataColumn )
myDataRow = myDataTable.NewRow
myDataRow("PicNumber") = 1
myDataRow("ImagePath") = "C:\test.bmp"
myDataTable.Rows.Add(myDat aRow)
myDataset.Tables.Add(myDat aTable)
'Add the image column to the table
AddImageColumn(myDataTable , "Image")
myDataset.WriteXmlSchema(" C:\Image.x sd")
'Load the images into the dataset
LoadAllImages(myDataTable, "ImagePath", "Image")
crpCR1 = New DundasTest
crpCR1.setdatasource(myDat aset)
************************** ********** ********** ********** *******
Public Sub AddImageColumn(ByVal myDataTable As DataTable, ByVal fieldName As String)
Try
Dim myDataColumn As New DataColumn(fieldName, Type.GetType("System.Byte[ ]"))
myDataTable.Columns.Add(my DataColumn )
Catch ex As Exception
MsgBox(Err.Description & " - " & ex.InnerException.ToString )
End Try
End Sub
Public Sub LoadAllImages(ByVal myDataTable As DataTable, ByVal filePathField As String, ByVal ImageField As String)
Try
Dim myDatarow As DataRow
For Each myDatarow In myDataTable.Rows
LoadImage(myDatarow, ImageField, myDatarow(filePathField).T oString)
Next
Catch ex As Exception
MsgBox(Err.Description & " - " & ex.InnerException.ToString )
End Try
End Sub
Public Sub LoadImage(ByVal myDataRow As DataRow, ByVal ImageField As String, ByVal FilePath As String)
Try
FilePath = "C:\test.bmp"
Dim fs As New IO.FileStream(FilePath, IO.FileMode.Open)
Dim image() As Byte
Dim br As New IO.BinaryReader(fs)
image = br.ReadBytes(CInt(fs.Lengt h))
myDataRow(ImageField) = image
fs.Close()
br.Close()
Catch ex As Exception
MsgBox(ex.InnerException.T oString)
End Try
End Sub
I got it working.
For everyone else: Execute your code so that the XML file creates, then base your report off of the XML file. When you go to run the report 'for real', simply use: myReport.SetDataSource(myD
The VB.Net code is posted below:
**************************
Dim myDataset As New DataSet
Dim myDataTable As DataTable
Dim myDataRow As DataRow
myDataTable = New DataTable
Dim myDataColumn As New DataColumn
myDataColumn = New DataColumn("PicNumber", Type.GetType("System.Int32
myDataTable.Columns.Add(my
myDataColumn = New DataColumn("ImagePath", Type.GetType("System.Strin
myDataTable.Columns.Add(my
myDataRow = myDataTable.NewRow
myDataRow("PicNumber") = 1
myDataRow("ImagePath") = "C:\test.bmp"
myDataTable.Rows.Add(myDat
myDataset.Tables.Add(myDat
'Add the image column to the table
AddImageColumn(myDataTable
myDataset.WriteXmlSchema("
'Load the images into the dataset
LoadAllImages(myDataTable,
crpCR1 = New DundasTest
crpCR1.setdatasource(myDat
**************************
Public Sub AddImageColumn(ByVal myDataTable As DataTable, ByVal fieldName As String)
Try
Dim myDataColumn As New DataColumn(fieldName, Type.GetType("System.Byte[
myDataTable.Columns.Add(my
Catch ex As Exception
MsgBox(Err.Description & " - " & ex.InnerException.ToString
End Try
End Sub
Public Sub LoadAllImages(ByVal myDataTable As DataTable, ByVal filePathField As String, ByVal ImageField As String)
Try
Dim myDatarow As DataRow
For Each myDatarow In myDataTable.Rows
LoadImage(myDatarow, ImageField, myDatarow(filePathField).T
Next
Catch ex As Exception
MsgBox(Err.Description & " - " & ex.InnerException.ToString
End Try
End Sub
Public Sub LoadImage(ByVal myDataRow As DataRow, ByVal ImageField As String, ByVal FilePath As String)
Try
FilePath = "C:\test.bmp"
Dim fs As New IO.FileStream(FilePath, IO.FileMode.Open)
Dim image() As Byte
Dim br As New IO.BinaryReader(fs)
image = br.ReadBytes(CInt(fs.Lengt
myDataRow(ImageField) = image
fs.Close()
br.Close()
Catch ex As Exception
MsgBox(ex.InnerException.T
End Try
End Sub
ASKER
By the way, I graded the answer as a "B" because I felt that ebolek could have done a better job explaining what he was doing in his other post.
whatever you feel but this should have saved you from long hours of trying to find how to do this.
ASKER
I'm not denying that you saved me MUCH time. Just after I read through your other post, I felt that you didn't do a very good job explaining. You pretty much put the code out there and said 'here it is'. Anyway. Good solution and I appreciate your help. You still got 1500 pts.
Thanks again.
Thanks again.
http://support.businessobjects.com/communityCS/FilesAndUpdates/cr9_vb_rdc_loadpic.exe.asp
I'll look for a .net example
mlmcc