Click here to Skip to main content
16,020,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am still trying to display an image from my Ms Access to a Picture Box. my project contains only a form and a picturebox. Each time I run the program it prompt up an error msg " Parameter is not Valid ". This is where I get the Error Msg.

myImage = Image.FromStream(myStream)

Below is my Code. I am in need of assistance to get this image displayed. Thanks.


VB
Imports System.Data.OleDb
Imports System.IO

Public Class Form1
    Dim myConnectionString As String
    Dim myConnection As OleDbConnection
    Dim myAdapter As OleDbDataAdapter
    Dim myDataset As DataSet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        InitializeComponent()
        '' Code for Initialize ConnectionString
        myConnectionString = " Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Users\Bekesoft\Desktop\Programming\Pic Dbase.mdb"

        myConnection = New OleDbConnection(myConnectionString)
        Try
        Catch ex As Exception
        End Try

        myConnection.Open()
        myAdapter = New OleDbDataAdapter("SELECT Photograph FROM Picture", myConnection)
        myDataset = New DataSet
        myAdapter.Fill(myDataset)
        myConnection.Close()

        Dim myByte() As Byte = CType(myDataset.Tables(0).Rows(0)(0), Byte())

        Dim myImage As Image
        Dim myStream As New MemoryStream(myByte, 0, myByte.Length)
        myImage = Image.FromStream(myStream)

        PictureBox1.Image = Image.FromStream(myStream)


    End Sub

End Class
Posted
Comments
Sandeep Mewara 1-Sep-10 15:41pm    
Check for myStream if it's null?

1 solution

The error means that your byte data is not a valid image. The most likely reason is that you failed to store your image data properly in the first place, or you're reading the wrong data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900