Loading PictureBox Image From Database

后端 未结 3 2084
逝去的感伤
逝去的感伤 2020-12-03 22:18

i\'m trying to load images from database to a PictureBox. I use these following codes in order to load them to my picture. I\'ve written some code but don\'t kn

3条回答
  •  温柔的废话
    2020-12-03 22:59

    Continue with something like this in the button1_Click:

    // Your code first, here.
    
    var da = new SqlDataAdapter(cmd);
    var ds = new DataSet();
    da.Fill(ds, "Images");
    int count = ds.Tables["Images"].Rows.Count;
    
    if (count > 0)
    { 
        var data = (Byte[])ds.Tables["Images"].Rows[count - 1]["Image"];
        var stream = new MemoryStream(data);
        pictureBox1.Image = Image.FromStream(stream);
    } 
    

提交回复
热议问题