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

        con.Open()

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

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

            For inc = 0 To (MaxRows - 1)

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

                    Itag_Found = True
                    Ifound_ID = inc

                Else
                    Itag_Found = False

                End If

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

        Finally
            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!!

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

Hi!

My guess is that you are not using a constructor with valid number of arguments.

Is this line:

ds.Tables("Patient Database").Rows(inc).Item("ID")

returns an image OR "ID" is some path of the image???

here are the list of constructors for Bitmap class:

http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.aspx

Please use the appropriate constructor according to your need.

Crap, forgot about this thread!!! thanks for the help guys, got it working.

commented: what is crap ? -3
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.