Loading PictureBox Image From Database

c#, sql-server

Solution

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);
} 

Problem

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 know what I should do for continuing. Any help will be appreciated. ``` private void button1_Click(object sender, EventArgs e) { sql = new SqlConnection(@"Data Source=PC-PC\PC;Initial Catalog=Test;Integrated Security=True"); cmd = new SqlCommand(); cmd.Connection = sql; cmd.CommandText = ("select Image from Entry where EntryID =@EntryID"); cmd.Parameters.AddWithValue("@EntryID", Convert.ToInt32(textBox1.Text)); } ```

Original source