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