Hi all,

I got a problem with part of my application, it's an exception I've never seen before.

Overload resolution failed because no accessible 'New' can be called without a narrowing conversion:
'Public Sub New(original As System.Drawing.Image)': Argument matching parameter 'original' narrows from 'Object' to 'System.Drawing.Image'.
'Public Sub New(stream As System.IO.Stream)': Argument matching parameter 'stream' narrows from 'Object' to 'System.IO.Stream'.
'Public Sub New(filename As String)': Argument matching parameter 'filename' narrows from 'Object' to 'String'. C:\Documents and Settings\user\Desktop\thornhill2011\malachy\WindowsApplication1\WindowsApplication1\Home.vb 201 23 WindowsApplication1

Private Sub DisplayImage()

        Dim ds As New DataSet
        Dim inc As Integer = 0
        Dim MaxRows As Integer
        Dim da As New OleDb.OleDbDataAdapter
        Dim con As New OleDb.OleDbConnection
        Dim dbProvider As String
        Dim dbSource As String
        Dim sql As String
        Dim Itag_Found As Boolean = False
        Dim Ifound_ID As Integer = 0

        dbProvider = "Provider = Microsoft.ACE.OLEDB.12.0;"
        dbSource = "Data Source = C:\Documents and Settings\user\Desktop\thornhill2011\malachy\WindowsApplication1\WindowsApplication1\Patient Database.mdb;Persist Security Info = True;"

        con.ConnectionString = dbProvider & dbSource


        sql = "SELECT * FROM ImageTable"
        da = New OleDb.OleDbDataAdapter(Sql, con)
        da.Fill(ds, "Patient Database")

        MaxRows = ds.Tables("Patient Database").Rows.Count

            For inc = 0 To (MaxRows - 1)

                If UID = ds.Tables("Patient Database").Rows(inc).Item("ID") Then

                    Itag_Found = True
                    Ifound_ID = inc

                    Itag_Found = False

                End If

            If Itag_Found = True Then

                Dim i As Array

                'Using Bmp As New Bitmap("C:\Documents and Settings\user\Desktop\thornhill2011\malachy\WindowsApplication1\WindowsApplication1\My Images\Flowers.jpg")
                Using Bmp As New Bitmap(ds.Tables("Patient Database").Rows(inc).Item("ID"))

                    Using MS As New MemoryStream
                        Bmp.Save(MS, ImageFormat.Jpeg)

                        i = MS.ToArray

                    End Using
                End Using

                Dim ImgStream As MemoryStream = New MemoryStream(CType(i, Byte()))
                Home_PictureBox.Image = New Bitmap(ImgStream)

            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)

            Windows.Forms.Cursor.Current = Cursors.Default

        End Try
    End Sub

The commented out line works just fine, it searches a system folder with no problems, but the line under it is ment to search a database for an image. I've tried to set the option "strict" to off but it makes no difference, anyone with any advice would be great as I'm truly stumped with this one!!

6 Years
Discussion Span
Last Post by Gazzmonkey

The message states that the contents of ds.Tables("Patient Database").Rows(inc).Item("ID") is not a valid image.

Even if it was, an image is a large binary object, that has an special treatement to be retrieved (see here)

Is best to save in the database only the path to the image (normally will occupy less space). Then use the Image.FromFile(ds.Tables("Patient Database").Rows(inc).Item("PathToFileImage")) to get the bitmap.

Hope this helps

This question has already been answered. 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.