how to put image in crytal report from database mysql

Posted by Jerome under VB.NET on 5/5/2012 | Points: 10 | Views : 2576 | Status : [Member] | Replies : 2
I want to put an image to crytal report from database with a blob type...Please show me the code on how to do it?Thanks




Responses

Posted by: Bugwee on: 5/7/2012 [Member] Starter | Points: 25

Up
0
Down
http://www.aspdotnet-suresh.com/2012/02/dynamically-display-images-in-crystal.html

Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sandeepkasar on: 5/13/2012 [Member] Starter | Points: 25

Up
0
Down

Hi,
Its vb code well you can get convert in C# if needed...

1.Create a table (e.g. ImageTable) having a column as Image datatype
i.e

CREATE TABLE ImageTable (
[Img] [image] NOT NULL ,
[ImgName] [nvarchar] (250) NOT NULL
)


2.// FileName is Physical path of your .jpg file

Public Function UploadFile(ByVal FileName As String) As Boolean
If (Not File.Exists(FileName)) Then
Return False
End If
Dim fs As FileStream = Nothing
Try
fs = New FileStream(FileName, FileMode.Open)
Dim fi As FileInfo = New FileInfo(FileName)
Dim temp As Long = fi.Length
Dim lung As Integer = Convert.ToInt32(temp)
Dim picture As Byte() = New Byte(lung - 1) {}
fs.Read(picture, 0, lung)
fs.Close()
Dim result As Boolean = PictureUploadToDB(picture, fi.Name)
Return result
Catch e As Exception
Console.WriteLine(e.Message & " - " & e.StackTrace)
Return -1
End Try
End Function


3.
Private Function PictureUploadToDB(ByVal picture As Byte(), ByVal fileName As String) As Boolean
Dim SqlQry As String
Dim cmd1 As New SqlCommand
SqlQry = "UploadFile"
cmd1.Parameters.AddWithValue("@Img", picture)
cmd1.Parameters.AddWithValue("@ImgName", fileName)
cmd1.Parameters.AddWithValue("@SpType", IIf(cmbShirtPant.Text = cmbShirtPant.Items.Item(0), "S", "P"))
cmd1.Parameters.AddWithValue("@Flag", 0)
Cn1.Open()
cmd1.Connection = Cn1
cmd1.CommandText = SqlQry
cmd1.CommandType = CommandType.StoredProcedure
Try
cmd1.ExecuteNonQuery()
PictureUploadToDB = True
Catch ex As Exception
MsgBox(ex.Message)
PictureUploadToDB = False
Finally
cmd1.Parameters.Clear()
Cn1.Close()
End Try
End Function

4
// stored proc in SQL DB


CREATE PROCEDURE dbo.UploadFile
@Img image,
@ImgName nvarchar(250),
AS
Begin
insert into ImageTable values(@Img,@ImgName)
End
GO

Finally you will get Images gets added to your table and use this table into your Crystal Reports
Plz Reply








Jerome, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response