0

Any help is much appreciated, guys. I tried using the dataset and other solutions to no avail. The error I keep getting is "Parameter is not valid." My code is this:

try
        {
            conn.Open();

            MySqlCommand comm = new MySqlCommand("SELECT lastname, firstname, picture FROM casestudyprofile WHERE caseid = " + id, conn);
            MySqlDataAdapter adp = new MySqlDataAdapter(comm);
            DataTable dt = new DataTable();

            adp.Fill(dt);

            if (dt.Rows.Count > 0)
            {

                lblname.Text = dt.Rows[0]["firstname"].ToString() + " " + dt.Rows[0]["lastname"].ToString();


                pbox2.Image = Image.FromStream(new MemoryStream((byte[])dt.Rows[0]["picture"]));

            }

            conn.Close();
        }
N. Tanaka
  • 37
  • 8
  • 1
    The error seems triggered from byte array stored in `MemoryStream` here: `Image.FromStream(new MemoryStream((byte[])dt.Rows[0]["picture"]))`. Check https://stackoverflow.com/questions/6712557/image-fromstream-parameter-not-valid for similar problem. – Tetsuya Yamamoto Jul 20 '17 at 02:58
  • Your code is fine. You should check if the `picture` column has data of not (it's probably a `blob` column, I guess). – Bob Dust Jul 20 '17 at 05:48
  • @BobDust Yes it's a blob column. I'll double check again. Thanks. – N. Tanaka Jul 21 '17 at 09:32
  • @TetsuyaYamamoto Based on ur link, I tried to use Bitmap like this: `pbox2.Image = new Bitmap(new MemoryStream((byte[])dt.Rows[0]["picture"]));` Sadly, still the same error. The picture in database is PNG, data type BLOB. – N. Tanaka Jul 21 '17 at 10:07

0 Answers0