Can we Store Images in an array ? How this can be done ?

Posted by .Netlearner under ASP.NET on 6/6/2012 | Points: 10 | Views : 1365 | Status : [Member] | Replies : 5
Hello All,
I want to display latest five product images from the database in 5 seperate image control.How this can be implemented ?

For String I have writtern as follows,
   cmd = new SqlCommand("select  TOP 4 ProductName,ProductImage FROM Products ORDER BY ProductId DESC", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
product[index] = dr["ProductName"].ToString();
index++;
}
dr.Close();

lblproduct1.Text=product[0].toString();
lblproduct2.Text=product[1].toString();


In Similar way i want to display images also.kindly Guide me




Responses

Posted by: Vuyiswamb on: 6/6/2012 [Member] [MVP] [Administrator] NotApplicable | Points: 25

Up
0
Down
an image is stored in a Bytes Field, so you need to retrieve the image and pass it to the Byte Array variable and directly bind the image control from a datasource property and it will show your images from the DB

Thank you for posting at Dotnetfunda
[Administrator]

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

Posted by: .Netlearner on: 6/7/2012 [Member] Starter | Points: 25

Up
0
Down
I didnt get it Can u pls help me with the example code ?

Am having 5 image controls and many images on the database.i want to display only the lastly added five images to the control how this can be done ?

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

Posted by: Ajay.Kalol on: 6/7/2012 [Member] Starter | Points: 25

Up
0
Down
Don't store whole Image in DB, just store its Name and at runtime retrieve it from its Path by its Name;

Use Databind control like repeater for this,Don't use separate 5 Image control.
OR Fast way if you want to Just Display then Use dynamic created HTML to display.
set image Path in Databound event if you use databind control.

for your lastly added 5 image query :
SELECT TOP 5 imgID,imgName from Table Order By InsertionDate desc



Ajay
ajaypatelfromsanthal.blogspot.in

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

Posted by: CGN007 on: 6/7/2012 [Member] Silver | Points: 25

Up
0
Down
Hope you see this...
http://www.dotnetfunda.com/articles/article1084-saving-images-into-the-database-in-aspnet-and-displaying-to-the-gridview.aspx

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

Posted by: CGN007 on: 6/23/2012 [Member] Silver | Points: 25

Up
0
Down
Mark as Answer if its helpful to you,that motivates...

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

Login to post response