# I need on my SQL (Retrieving Images)

**URL:** <https://forum.kirupa.com/t/i-need-on-my-sql-retrieving-images/256949>\
**Category:** programming\
**Created:** [April 9, 2008, 1:51am UTC](https://forum.kirupa.com/t/i-need-on-my-sql-retrieving-images/256949 "2008-04-09T01:51:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rai\_87](https://avatars.discourse-cdn.com/v4/letter/r/e0b2c6/32.png) [@Rai\_87](https://forum.kirupa.com/u/Rai_87)\
**Post date:** [April 9, 2008, 1:51am UTC](https://forum.kirupa.com/t/i-need-on-my-sql-retrieving-images/256949/1 "2008-04-09T01:51:21Z")

</div>

I need to do a coding for inserting (done) and retrieving a image on sql using blob (binary large object) but i have sample of the previous student and i cannot do same coding as the previous student. Pls help me on the coding… ur help will be appriecated…👼

// Retrieving images

[SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] Button1\_Click([/SIZE][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][SIZE=2] sender, [/SIZE][SIZE=2][COLOR=#008080]EventArgs[/COLOR][/SIZE][SIZE=2] e)  
{  
[/SIZE][SIZE=2][COLOR=#008000]// Put user code to initialize the page here  
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][SIZE=2] id = DropDownList1.SelectedItem.Value;  
[/SIZE][SIZE=2][COLOR=#008080]MemoryStream[/COLOR][/SIZE][SIZE=2] stream = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]MemoryStream[/COLOR][/SIZE]SIZE=2;  
[/SIZE][SIZE=2][COLOR=#008080]SqlConnection[/COLOR][/SIZE][SIZE=2] connection = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]SqlConnection[/COLOR][/SIZE]SIZE=2;  
[/SIZE][SIZE=2][COLOR=#0000ff]try  
[/COLOR][/SIZE][SIZE=2]{  
connection.Open();  
[/SIZE][SIZE=2][COLOR=#008080]SqlCommand[/COLOR][/SIZE][SIZE=2] command = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]SqlCommand[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#800000]“select ImageBinary from ImageTable where id=”[/COLOR][/SIZE][SIZE=2] + id + [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2], connection);  
[/SIZE][SIZE=2][COLOR=#0000ff]byte[/COLOR][/SIZE][SIZE=2][] image = ([/SIZE][SIZE=2][COLOR=#0000ff]byte[/COLOR][/SIZE][SIZE=2][])command.ExecuteScalar();  
stream.Write(image, 0, image.Length);  
[/SIZE][SIZE=2][COLOR=#008080]Bitmap[/COLOR][/SIZE][SIZE=2] bitmap = [/SIZE][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#008080]Bitmap[/COLOR][/SIZE]SIZE=2;  
Response.ContentType = [/SIZE][SIZE=2][COLOR=#800000]“image/jpeg”[/COLOR][/SIZE][SIZE=2];  
bitmap.Save(Response.OutputStream, [/SIZE][SIZE=2][COLOR=#008080]ImageFormat[/COLOR][/SIZE][SIZE=2].Jpeg);  
}  
[/SIZE][SIZE=2][COLOR=#0000ff]finally  
[/COLOR][/SIZE][SIZE=2]{  
connection.Close();  
stream.Close();  
}  
}  
}  
[/SIZE]
