Click here to Skip to main content
14,690,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Experts,

Here I have Inserted my images into Access Database. And I am able to Retrieve those Images using Max(ID) Or Image (ID).

But Here My Requirement is to Get Image using List box. For Example I Retrieved My Images List Into List-box From Database. Now When I click on a image in list-box it should be Passed to Picture box.

I am Trying to get Image Using Below Code.

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox l = sender as ListBox;
if (l.SelectedIndex != -1)
{
listBox1.SelectedIndex = l.SelectedIndex;
listBox1.Text = listBox1.SelectedIndex.ToString();
LoadPicture();
}

}


private void LoadPicture()
{
con.Open();
cmd.CommandText = "select picture from pictures where id ='" + listBox1.SelectedIndex.ToString() + "'";
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
OleDbCommandBuilder cbd = new OleDbCommandBuilder(da);
DataSet dst = new DataSet();
da.Fill(dst);
con.Close();
byte[] ap = (byte[])(dst.Tables[0].Rows[0]["picture"]);
MemoryStream ms = new MemoryStream(ap);
pictureBox1.Image = Image.FromStream(ms);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.BorderStyle = BorderStyle.Fixed3D;
label1.Text = listBox1.Text.ToString();
ms.Close();
}



While Executing this Code I am Getting Error Like Below.

""An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll""

""Additional information: Data type mismatch in criteria expression.""

How to overcome this Problem. Please Help me.


Thanks in Advance.
Posted

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