I made website for the computer shop,i have to display image & price of the components for that i made sql database(laptop.mdf) with columns(model_no as varchar(50),company as varchar(50),price as int,picture as image). image of component is stored in the picture column.i an already inserted image directly by writing sql query ,now i want to display that image on webpage in ASP.NET

I made website for the computer shop,i have to display image & price of the components for that i made sql database(laptop.mdf) with columns(model_no as varchar(50),company as varchar(50),price as int,picture as image). image of component is stored in the picture column.i an already inserted image directly by writing sql query ,now i want to display that image on webpage in ASP.NET

snapshot

I thought that pulling images from a database was quite an expensive operation. Why not store the file path in the database and then just set the imageurl parameter of the <asp:image> tag to the path you read out of the database. This would be eaiser and would not require a handler to process the image.

If you are always going to store the images in the same directory. You can just store the filename in the database and append the correct path before setting the imageurl.

hi

I was dealing with the same scenario and i found out storing image in the database is not the best option-takes more download time and still u'll write more code.

The best thing to do is store the images in a file directory in your project folder and then store pointers/paths in database to those images.You'll just need a server-side file upload control like that for attachments on mail applications and provide code for limiting upload of images only.

You'll need to import the the input/ouput(IO) namespace in your page that uses the file class.The sample code can look as below:

<%@import namespace="System.IO"%>  'appears in your code behind or before script tag 'if your code is embedded

'upload image to a server directory,given a fileupload control named fileupload

'use the instr() strings class to test for valid images .jpg, .jpeg, etc depending on 'the what you wish to upload.

fileupload.saveas(server.mappath("path to folder/")& fileupload.filename)

'write a parameterized query using a sql command to insert the image pointer(string 'path) to database.if u have problems on writing the query get back to me.for now 'try this

for display u just need to retrieve the records that you need plus the image path for each record.You then formulate an image tag(<img/>) tag using the response.write() object and pass the image to browser.You need to add styles like height,width and position for the image to display correctly.I'm assumiong you're comfortable with datasets and ado.net as a whole.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.