Hi everyone!

I'm trying to display the logo for a particular supplier but I always end up with an error picture.

here's my code:

Imports System.Data.OleDb
Imports System.Data

Public Class SupplierDetails
Dim objConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Cristy\Desktop\InventorySystem\InventorySystem\inventory.mdb")

"SELECT Supplier, ContactPerson, PhoneNumber, FaxNumber, " & _
"Email, Website, Address, LogoPath " & _
"FROM SupplierDetails " & _
"ORDER BY Supplier", objConnection)

Dim objDataSet As DataSet
Dim objDataView As DataView
Dim objCurrencyManager As CurrencyManager

Private Sub FillDataSetAndView()
objDataSet = New DataSet()
objDataView = New DataView(objDataSet.Tables("SupplierDetails"))
objCurrencyManager = CType(Me.BindingContext(objDataView), CurrencyManager)
End Sub

Private Sub BindFields()
'clear any previous bindings...
lblSupplier.DataBindings.Clear()
lblContactPerson.DataBindings.Clear()
lblContactNumber.DataBindings.Clear()
lblFaxNumber.DataBindings.Clear()
lblWebsite.DataBindings.Clear()
lblEmail.DataBindings.Clear()
CompanyLogo.DataBindings.Clear()

'Add new bindings to the DataView object...
CompanyLogo.ImageLocation = CStr(objDataSet.Tables(0).Rows(0)("LogoPath"))

End Sub

Private Sub ShowPosition()

'Display the current position and the number of recors
txtRecordPosition.Text = objCurrencyManager.Position + 1 & _
" of " & objCurrencyManager.Count()
End Sub

Private Sub SupplierDetails_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
FillDataSetAndView()
BindFields()
ShowPosition()

End Sub


I tried checking if the path that is on my db is correct and it is. So most probably my code is the one at fault

 CompanyLogo.ImageLocation = CStr(objDataSet.Tables(0).Rows(0)("LogoPath"))


Its probably this one, I'm not sure how to do this properly can someone help me pls?

3
Contributors
2
Replies
19
Views
4 Years
Discussion Span
Last Post by TnTinMN

If the CompanyLogo object is a picturebox or image, you need to do something like this:

If File.Exists(CStr(objDataSet.Tables(0).Rows(0)("LogoPath"))) Then
If TypeOf CompanyLogo Is PictureBox Then
CompanyLogo.BackgroundImage = Image.FromFile(CStr(objDataSet.Tables(0).Rows(0)("LogoPath")))
ElseIf TypeOf CompanyLogo Is Image Then
CompanyLogo = Image.FromFile(CStr(objDataSet.Tables(0).Rows(0)("LogoPath")))
Else
MsgBox("Type not determined")
End If
Else
End If


Edited by Begginnerdev

Are you using a relative or absolute path. If it is a relative path, it will be relative to the current working directory.

Try adding this to your code to retrieve the PictureBox's error reason.

   Private Sub CompanyLogo_LoadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles CompanyLogo.LoadCompleted
If e.Error IsNot Nothing Then
MsgBox(e.Error.Message)
End If
End Sub

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.