Solved

How to display images from database in gridview.

Posted on 2008-10-01
4
3,669 Views
Last Modified: 2012-05-05
Ok, so i realise this may be going over some well trodden ground but I am yet to get this down. Thanks to a couple of other informative posts, I have been able to insert actual image data int an sql data base (i was originally thinking that this functionality may have been built in to Visual Web Developer). Now I would like to be able to display these images in a gridview for website gallery purposes. I would like the website owner to be able to upload extra images into the database table and have the gallery automatically updated. So, the gallery using images from "Pics of item x" table (for example) may have 15 images to start with. Owner gets, say, a five more images, uploads to the database and next time the gallery is displayed, the extra images are included. So far I have only found partial answers, that is, being a beginner, I am requiring a few more of the gaps filled in. For example there is an answer here http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23181647.html  "02.22.2008 at 03:30AM PST, ID: 20956279". I get most of this except for the implimentation of the Response.Outputstream from GridImageTemplate.aspx. I am unsure about the call to the page and how the page is set up (fully).

Hoping for an answer as this is doing me in.

Thanks in advance from a nooby.
0
Comment
Question by:finnatic
  • 2
4 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 22621883
Several good articles (with full explanation)

Storing Images to Database and Retrieving to GridView
http://www.beansoftware.com/asp.net-tutorials/images-database.aspx

Displaying Images in a Gridview using SQL Database
http://www.dotnet-friends.com/Articles/ASP/ARTinASP27c1c67b-0483-4d8d-9fca-86d066d03aa7.aspx

Inserting Images into Database and Display it in GridView through Handler.ashx
http://www.aspdotnetcodes.com/Insert_Images_Database.aspx

Database driven images in ASP.NET GridView
http://isom.uoregon.edu/community/blogs/castner/archive/2007/03/08/Database-driven-images-in-ASP.NET-2-GridView.aspx

Displaying Image in Gridview from Database
http://www.codeproject.com/KB/aspnet/GridImage.aspx
0
 

Author Comment

by:finnatic
ID: 22631635
Thanks Dhaest;

Still one or two probs... I am using the solution on beansoftware as it most closely resembles my problem.
I am having to convert code to C# though and something is still going wrong.
I am getting an  Incorrect syntax near '=' in an exception helper which is hanging off the line dA.Fill(ds).
I don't know my connection string is wrong maybe. I have tried variations on this to no avail.
Also, the solution says that   "Create a new-page, Viewer.aspx and add a GridView onto it. (This page is linked from the Default.aspx page via lnkView)." I am unsure about the lnkView... Is this a setting I must apply or is it automatic???

Thanks again (nearly there)...
 protected void Page_Load(object sender, EventArgs e)

    {

        

        string strSQL = "SELECT * FROM Iimage WHERE business_id = " + Request.QueryString["business_id"];

        string connString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ConnectionString;
 

        DataSet dS = new DataSet();

        SqlDataAdapter dA = new SqlDataAdapter(strSQL, connString);

        byte[] arrContent;

        

        dA.Fill(dS);

        DataRow dR;

        dR = dS.Tables[0].Rows[0];
 

        arrContent = (byte[])dR.ItemArray.GetValue(1);

    }

Open in new window

0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22631878
My guess would be that the query string does not contain a valid value for business_id. e.g. if its missing or blank then you would be creating your invalid sql near =.

Is your table actually called Iimage with the double i?

Once you have this working you may want to look into the issues of 'sql injection'. Your current code will let users alter your sql and maybe do some naughty things.
0
 

Accepted Solution

by:
finnatic earned 0 total points
ID: 22684897
THe spelling is correct on that file Iimages.....
MIght have to put this on hold for now.. I have bigger problems afoot....
Cheers.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now