an error shows saying that I have invalid parameters for this code... can anyone tell me whats wrong? Im supposed to get the image assigned to the clientID.
This piece of code might come in handy. I have tried it.
byte[] imagedata = (byte [])dataGridView1[4, dataGridView1.SelectedRows[0].Index].Value;
using (System.IO.MemoryStream ms = new System.IO.MemoryStream(imagedata, 0, imagedata.Length))
{
ms.Write(imagedata, 0, imagedata.Length);
//Set image variable value using memory stream.
image = Image.FromStream(ms, true );
}
this code works. MySql Wamp.
using System.IO;
string appPath = Path.GetDirectoryName(Application.Executable) + @"/student Images/";
string imagename;
//put this code below to load form.
getimage();
if(File.Exist(appPath + imagename)
{
PictureBox1.Image = Image.FromFile(appPath + imagename);
}
else
{
PictureBox1.Image = Properties.Resources.Image_notfound;
}
private void getimage()
{
MySqlConnection connect = new MySqlConnection(con);
MySqlCommand cmd = new MySqlCommand("SELECT PictureName as 'pic' FROM userprofile where ID='" + datagrid.CurrentRow.Cells["ID"].ToString() + "'");
cmd.CommandType = CommandType.Text;
cmd.Connection = connect;
connect.Open();
Try
{
MySqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
imagename = dr.GetString("pic");
}
dr.Close();
}
catch(Exception ee)
{
Console.WriteLine(ee.ToString());
}
finally
{
connect.Close();
}