hi,
how can i dispaly image file like jpg, gif etc. from sql database to gridview or aspx page in asp.net.
thanking u all in advance
anu bajracharya
hi,
how can i dispaly image file like jpg, gif etc. from sql database to gridview or aspx page in asp.net.
thanking u all in advance
anu bajracharya
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rekha SinghPosted Dec 28, 2009, 7:05 AM
write this code on page load of ur aspx page
//build our query statement
string sqlText = "SELECT PassPicture FROM PassportDetails WHERE empcode = 123 ";
SqlConnection connection = new SqlConnection("Your ConnectionString Here");
SqlCommand command = new SqlCommand(sqlText, connection);
//open the database and get a datareader
connection.Open();
SqlDataReader dr = command.ExecuteReader();
dr.Read();
Response.Clear();
byte[] buffer = (byte[])dr["PassPicture"];
int blen = ((byte[])dr["PassPicture"]).Length;
Response.OutputStream.Write(buffer, 0, blen);
Response.End();
connection.Close();
this code will display the image in ur aspx page
Niradhip ChakrabortyPosted Apr 16, 2009, 6:05 AM
I think, I have already sent you the code concept. Only thing you need to do is giving proper image path for different size of image.
Checkout the following articles to display images in gridview.
1. http://www.devasp.net/net/articles/display/692.html
2. http://www.aspxcode.net/free-asp-net-data-sample-source-code.aspx?Topics=How%20to%20display%20images%20in%20GridView
Ruchi RPosted Apr 16, 2009, 5:38 AM
thanks for ur reply,
can u plz send me c# code to do this...........
Niradhip ChakrabortyPosted Apr 16, 2009, 3:19 AM
Ruchi RPosted Apr 16, 2009, 2:44 AM
hi all,
Actually i need to display pictures in gridview in thumbnail size . when user clicks on the thumbnail picture , large sized picture should be displayed.Is it possible to do .If yes then how can i do it.
Niradhip ChakrabortyPosted Apr 10, 2009, 1:33 PM
Say u have created the following
Now in your code behind get the image Path and display it.
Something like this.
imgEvent2.ImageUrl = dstEvents.Tables["Events"].Rows[intIndex]["evm_txt_EventImagePath"].ToString();
I am using dataset(dstEvents) to fetch the record from table.
Make sure the path contains the image correctly.
Blocked AccountPosted Apr 10, 2009, 4:56 AM
Hi
Take the reference of this article, this article will solve your problem.
http://www.aspsnippets.com/post/2009/02/21/Display-Images-from-Database-using-ASPNet.aspx
Ruchi RPosted Apr 10, 2009, 1:59 AM
Thanks for the reply,
i have stored image itself in the sql database.table for this contains following fields like image_id (int), image_name(varchar), image_data(image), image_contenttype(varchar).Now i need to display image name , image_data, and imagecontentype in a grid view or in aspx file.how can i do this?
waiting for ur reply
aru vPosted Apr 9, 2009, 8:05 AM
Hi,
Are you storing the Image path in SQL or the Image itself?
Thanks,
Aru
Ruchi RPosted Apr 9, 2009, 7:28 AM
Thanks for ur reply.
Actually i am new user of asp.net .So can u plz tell me how to do all this.Waiting for ur reply.
Gorgi MarkovskiPosted Apr 9, 2009, 6:46 AM