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")

    Dim objDataAdapter As New OleDbDataAdapter( _
   "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()
        objDataAdapter.Fill(objDataSet, "SupplierDetails")
        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()
        lblAddress.DataBindings.Clear()
        CompanyLogo.DataBindings.Clear()


        'Add new bindings to the DataView object...
        lblSupplier.DataBindings.Add("Text", objDataView, "Supplier")
        lblContactPerson.DataBindings.Add("Text", objDataView, "ContactPerson")
        lblContactNumber.DataBindings.Add("Text", objDataView, "PhoneNumber")
        lblFaxNumber.DataBindings.Add("Text", objDataView, "FaxNumber")
        lblWebsite.DataBindings.Add("Text", objDataView, "Website")
        lblEmail.DataBindings.Add("Text", objDataView, "Email")
        lblAddress.DataBindings.Add("Text", objDataView, "Address")
        CompanyLogo.ImageLocation = CStr(objDataSet.Tables(0).Rows(0)("LogoPath"))


        'Display a ready status...
        TS.Text = "Ready"
    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?

Recommended Answers

All 2 Replies

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
    MsgBox("Path not valid/File not found.")
End If

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
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.