retrieve image from database in image control

Posted by Rickeybglr under Regular Expressions on 8/16/2011 | Points: 10 | Views : 36328 | Status : [Member] | Replies : 9
hey i am able to store image into sql server but unable to display back on image control in aspx page. any suggestion will be thnkful..
i hv to display image, id & name on other page for ex: display.aspx. how can i do ths????

i am providing my SP and Code wat i hv writtn...


SP:
insert into DB :
ALTER PROCEDURE [dbo].[insertIntoImage](@id int,@name nvarchar (30),@image image)
AS
TRY
INSERT INTO image(imageid,name,images) VALUES (@id,@name,@image);
END;

Retrieve image:
AS
BEGIN
select imageid,images,name from image where imageid=@id
SET NOCOUNT ON;

code ....

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class Account_insert : System.Web.UI.Page
{

int Id;
string strName;
byte[] myimage;
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=demo_db;Integrated Security=true");
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnSubmit_Click(object sender, EventArgs e)
{
getInfo();
displayInfo();
}

public void getInfo()
{

Id = 0;
if(txtId.Text!="")
Id = Convert.ToInt32(txtId.Text);

strName = txtName.Text;

if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.FileName != "")
{

byte[] myimage = new byte[FileUpload1.PostedFile.ContentLength];
HttpPostedFile Image = FileUpload1.PostedFile;
Image.InputStream.Read(myimage, 0, (int)FileUpload1.PostedFile.ContentLength);

try
{
conn.Open();
SqlCommand cmdInsert = new SqlCommand("insertIntoImage", conn);
cmdInsert.CommandType = CommandType.StoredProcedure;
cmdInsert.Parameters.Add("@id", Id);
cmdInsert.Parameters.Add("@name", strName);
cmdInsert.Parameters.Add("@image", SqlDbType.Image, myimage.Length).Value = myimage;
cmdInsert.Parameters["@image"].Value = myimage;
cmdInsert.ExecuteNonQuery();
cmdInsert.Dispose();
}

catch (Exception ee)
{
ee.Message.ToString();
}

finally
{
conn.Close();
}
}
}

}




Responses

Posted by: A4u_6178 on: 8/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,
Refer this article...
http://www.dotnetfunda.com/articles/article1084-saving-images-into-the-database-in-aspnet-and-displaying-to-the-gridview-.aspx

Thanks & Regards,

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rickeybglr on: 8/16/2011 [Member] Starter | Points: 25

Up
0
Down
is ther any othr way 2do the same thing without using httphandler

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: A4u_6178 on: 8/16/2011 [Member] Starter | Points: 25

Up
0
Down
Have a look at this article..
http://www.codeproject.com/KB/database/ImageSaveInDataBase.aspx

Thanks & Regards,

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vforvijay on: 8/16/2011 [Member] Starter | Points: 25

Up
0
Down
hi refer the below link..
http://vbdotnetaddict.blogspot.com/2011/06/how-to-retrieve-uploaded-images-from.html

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Itorian on: 8/16/2011 [Member] Starter | Points: 25

Up
0
Down
You need to generate (build) the image url and u have stored the image in binary form in db. You can take the advantage of .ashx file which will do this for you.

Student of M.Tech IT | Microsoft MVP | Mindcracker MVP | IT Faculty | Blogger | Author

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Chikkanti on: 5/23/2012 [Member] Starter | Points: 25

Up
0
Down
hi... refer the following link
http://chikkanti.wordpress.com/2011/12/22/how-to-save-and-retrive-image-intofrom-sql-server-database-by-using-asp-net/

chikkanti

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bsimage on: 5/28/2013 [Member] Starter | Points: 25

Up
0
Down
the way of c# download image url can be found here, take a look at this sample and you will find it is useful for you to do this. check here: http://www.rasteredge.com/how-to/csharp-imaging/download-from-url/

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Arronlee on: 5/5/2014 [Member] Starter | Points: 25

Up
0
Down
Hi, Bsimage.
Have you ever tried this image control ( http://www.yiigo.com/guides/csharp/ ) before? I am testing about the related projects these days. Do you have any ideas about it? Or any good suggestion? Thanks in advance.



Best regards,
Arron


Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Belindar on: 12/16/2014 [Member] Starter | Points: 25

Up
0
Down
To retrieve image from database in image control, you may have a look at:
http://www.rasteredge.com/dotnet-imaging/image-processing-retrieve-information/

Enjoy Life, Love All!

Rickeybglr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response