8 Replies - 10041 Views - Last Post: 17 March 2012 - 11:37 PM Rate Topic: -----

#1 nishutank   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-February 12

Error is parameter is not valid

Posted 10 March 2012 - 05:07 AM

code to display image from the database into picturebox
database name:snapshot.mdb
table name:snapshottbl
image field:imagename[ole object type]
Imports System.Data.OleDb
Imports System.IO
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim connectionstring As String = "provider=microsoft.jet.oledb.4.0;data source=E:\PROJECT SPYSO SOFTWARES\database\snapshot.mdb;persist security info=false"
        Dim con As New OleDbConnection(connectionstring)
        Dim bs As New BindingSource
        con.Open()
        Dim query As String = "select * from snapshottbl"
        Dim dataadapter As OleDbDataAdapter
        Dim dataset As New DataSet
        dataadapter = New OleDbDataAdapter(query, con)
        dataadapter.Fill(dataset, "snapshottbl")
        bs.DataSource = dataset.Tables("snapshottbl")

       
        Dim cmd As New OleDb.OleDbCommand(query, con)
        Using dr As OleDb.OleDbDataReader = cmd.ExecuteReader()
            Using dt As New DataTable
                dt.Load(dr)
                Dim row As DataRow = dt.Rows(0)
        
                Using ms As New IO.MemoryStream(CType(row("imagename"), Byte()))
                    Dim img As Image = Image.FromStream(ms) //Error is parameter is not valid...
                    PictureBox1.Image = img
                End Using
            End Using
        End Using
        PictureBox1.DataBindings.Add("image", bs, "image")
        
    End Sub
End Class


This post has been edited by Atli: 10 March 2012 - 05:57 AM
Reason for edit:: Title updated. Please use descriptive, and accurate, thread titles.


Is This A Good Question/Topic? 0
  • +

Replies To: Error is parameter is not valid

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6535
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: Error is parameter is not valid

Posted 10 March 2012 - 01:42 PM

What line produces the error?

Line 30:
I'm pretty sure that PictureBox does not have a property called "image"
It does however have a property called "Image" - Though I've heard the VB.Net doesn't always care about case sensitivity, so this may not be an issue. But it costs you nothing to double check the case and use an exact match.

When you set bindings the 3 parameters are
(property in the target, source object, property in the source object)

your source object is 'bs' which is a binding source
15 bs.DataSource = dataset.Tables("snapshottbl")

YOu then have this
30 PictureBox1.DataBindings.Add("image", bs, "image")
So my question is: Does your source object 'bs' actually have a property of "image"?
Was This Post Helpful? 0
  • +
  • -

#3 DimitriV   User is offline

  • vexing conundrum
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,746
  • Joined: 24-July 11

Re: Error is parameter is not valid

Posted 10 March 2012 - 02:28 PM

Well, intellisense will auto-capitalize all of the procedures and properties unless of course the properties were created without capitalization. I see that in some custom classes.
Was This Post Helpful? 0
  • +
  • -

#4 nishutank   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-February 12

Re: Error is parameter is not valid

Posted 16 March 2012 - 02:17 AM

well its not working...how can i display image from access into picturebox in vb.net...i have tried using memorystream but its also not working...please help its urgent...my final year project is stopped because of this module only...
Was This Post Helpful? 0
  • +
  • -

#5 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Error is parameter is not valid

Posted 16 March 2012 - 02:33 AM

check this article. The examples are shown using SQL but try replacing everything SQL with OleDb. (ex: SqlConnection - OleDbConnection)
Was This Post Helpful? 0
  • +
  • -

#6 nishutank   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-February 12

Re: Error is parameter is not valid

Posted 17 March 2012 - 08:12 AM

i got the code...but the same problem here....
 Dim connection As New OleDbConnection("provider=microsoft.jet.oledb.4.0;data source=E:\PROJECT SPYSO SOFTWARES\database\spysonew.mdb;persist security info=false")
        Dim command As New OleDbCommand("SELECT picture FROM screenshots WHERE id=1", connection)
        connection.Open()
        Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
        connection.Close()
        Dim picture As Image = Nothing
        'Create a stream in memory containing the bytes that comprise the image.
        Using stream As New IO.MemoryStream(pictureData)
            'Read the stream and create an Image object from the data.   
            picture = Image.FromStream(stream) //error:parameter not valid.
        End Using
        PictureBox1.Image = picture


it is showing an error that parameter is not valid....please help it out.
Was This Post Helpful? 0
  • +
  • -

#7 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Error is parameter is not valid

Posted 17 March 2012 - 08:29 AM

what's the datatype you've set to the field which stores images?
Was This Post Helpful? 0
  • +
  • -

#8 nishutank   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 25-February 12

Re: Error is parameter is not valid

Posted 17 March 2012 - 11:26 PM

image is stored in access as a type OLE object
Was This Post Helpful? 0
  • +
  • -

#9 nK0de   User is offline

  • Catch me As Exception
  • member icon

Reputation: 206
  • View blog
  • Posts: 823
  • Joined: 21-December 11

Re: Error is parameter is not valid

Posted 17 March 2012 - 11:37 PM

aw shucks! You're using MS Access. This method worked for me for the datatype image in SQL Server. I dunno if there is a datatype in Access similar to that or else you'll have to find another solution. Sorry.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1