Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All
I have an error for retrieving images from Ms Access like this:
<<Parameters is not valid.>>

Although I copy the code from practical sample but I don't understand this Error:
C#
private void button1_Click(object sender, EventArgs e)
    {
        OleDbConnection myConnection = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);

        myConnection.Open();
        OleDbCommand cmd = new OleDbCommand("select * from [Images] where ID=1", myConnection);
        OleDbDataAdapter da = new OleDbDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);

        if (dt.Rows.Count > 0)
        {
            if (dt.Rows[0]["AImage"] != DBNull.Value)
            {
                pictureBox.Image = ByteArrayToImage((Byte[])dt.Rows[0]["AImage"]);
            }
        }
        myConnection.Close();   

    }

    Bitmap ByteArrayToImage(byte[] b)
    {
        MemoryStream ms = new MemoryStream();
        byte[] pData = b;
        ms.Write(pData, 0, Convert.ToInt32(pData.Length));
        Bitmap bm = new Bitmap(ms, false);
        ms.Dispose();
        return bm;
    }

The error has been shown in
C#
Bitmap bm = new Bitmap(ms, false);
Posted

1 solution

The problem is not with your code, its in your database, i think you should check the Data type of the column that you use to store your images and make sure that its Data Type is set to "OLE OBJECT" I hope this will help, thanks
 
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