I have created table "Image" in access database that have 3 fields "ImageId","ImageName" and "Image_Path". I added below code to form:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Con As OdbcConnection = New OdbcConnection
Dim Sql As String = "Select * from Image"
Con.ConnectionString = connstring
Dim da As OdbcDataAdapter = New OdbcDataAdapter(Sql, Con)
da.Fill(ds, "Image")
AddImageColumn(ds.Tables("Image"), "Image_stream")
For index As Integer = 0 To ds.Tables("Image").Rows.Count - 1
If Not String.IsNullOrEmpty(ds.Tables("Image").Rows(index).Item("Image_Path").ToString) Then
LoadImage(ds.Tables("Image").Rows(index), "Image_stream", ds.Tables("Image").Rows(index).Item("Image_Path").ToString)
Else
End If
Next
rptDoc.ReportSource = ds.Tables("Image")
End Sub
Private Sub AddImageColumn(ByVal objDataTable As DataTable, ByVal strFieldName As String)
Try
Dim objDataColumn As DataColumn = New DataColumn(strFieldName, Type.GetType("System.Byte[]"))
objDataTable.Columns.Add(objDataColumn)
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
Private Sub LoadImage(ByVal objDataRow As DataRow, ByVal strImageField As String, ByVal FilePath As String)
Try
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Dim Image() As Byte = New Byte(fs.Length) {}
fs.Read(Image, 0, CType(fs.Length, Integer))
fs.Close()
objDataRow(strImageField) = Image
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
End Sub
But I get filenotfound error on line:
Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Although that path contains image.Can any1 help me please?