简体   繁体   中英

How to retrieve blob image in mysql to datagridview using C#

I am using this syntax where the dr.getValue(6) is the blob image from mysql.

public void LoadRecords()
{
    metroGrid1.Rows.Clear();
    cm = new MySqlCommand("Select * from tblaccnt", cn);

    dr = cm.ExecuteReader();
    while (dr.Read())
    {
        metroGrid1.Rows.Add(dr.GetValue(0), dr.GetValue(1), dr.GetValue(2), dr.GetValue(3), dr.GetValue(4), dr.GetValue(5), dr.GetValue(6));

    }

    dr.Close();
}

But I always end up with Parameter is not valid Exception. Thanks in advance for the help

You have to set byte array for your image

  (byte[])reader["ImageData"] 

And then convert to Image

 MemoryStream ms = new MemoryStream((byte[])reader["ImageData"]);
 Image returnImage = Image.FromStream(ms);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM