Skip to main content
abstractindia
Participating Frequently
December 4, 2010
Question

How to get images dynamically from database without file paths in the table field

  • December 4, 2010
  • 2 replies
  • 2002 views

I have a MS-Access database. I am working with ASP.NET. In the database there is product table in which I have "CodeNo" as a field which is a text field, and the product codes like "SM-R-2035". I also have another field "Image" which is also a text field and which have a file path in it corresponding to the particular product Image (e.g. Images\Products\SM-R-2035.jpg). So far every thing is ok. I have to update this site very frequently and lots of images are added each and every time. Its a tedious work to type the paths and file name every time and it also take a lot of time.

What I am asking is : Is it possible to get images from a specific folder at runtime which is referenced by the "code no" itself and not the file path from the database. (Say at run time the "code no" is referenced from the database and the corresponding image is loaded dynamically from the specified folder). In other word I want to avoid the tedious work of typing.

Can any one help with this issue. Any other simple suggestions are welcome.

This topic has been closed for replies.

2 replies

ultrasuite
Inspiring
December 6, 2010

All you need to do is simple concatenation to obtain the path for the image file.  You didn't mention whether you are using VB.Net, C# or some other language to do your coding.

If the code in your database is SM-R-2035, the file name is SM-R-2035.jpg and the path to the images foilder is Images\Products\SM-R-2035.jpg, Conceptually here is what you need to do:

dim code_var

dim path_var


code_var = the code you obtain from your relevant field in the database


path_var = "Images\Products\" & code_var & ".jpg"

Now path_var is what you would call to obtain the image from your images folder.

abstractindia
Participating Frequently
December 7, 2010

Thanks Ultarsuit !

I am using VB.NET. But let me also admit that basically I am a designer and not a programmer. So writing some code for me is just like rocket science. Right now I am using Excel to concatenate the field values to get the path string and then using an "import external data" wizard in access to get that data.

You have suggested me the steps that I need to write the code in my .aspx document. I use dreamweaver's GUID by which I can place the recordset in my .aspx document visually (Just drag and drop or just click insert and dreamweaver does all coding for me)

Although I got the idea of declaring the variables and then concatenating the field values to get the string. I will definitely try and workout.

Thank you once again !

abstractindia
Participating Frequently
December 26, 2010

Were you able to make the concatenation work?

J.S.

http://ultrasuite.blogspot.com/


Here is my code :

<script runat="server">

Sub Page_Load( )

Dim fileName As String = Server.MapPath("Products\") &  dsproducts.FieldValue("CodeNo", Nothing) & ".jpg"

<img src="<%= fileName %>" width="96" height="96" id="image" />

End Sub

</script>

When I use Response.Write(fileName) I get the correct path

i.e. D:\WebSites\Testing Project\ASPdotNet\Products\SM-R-1232.jpg

But binding it to image is not working. Can you please guide me how to get it done.

Thank you in advance.

pziecina
Legend
December 4, 2010

Hi

Don't know if this is possible using an access database for the web, but you could use a look-up table just to prepend the file path to the image name.

See - http://www.trigonblue.com/AccessLookup.htm

Just have the file path in the access table as a separate entry and concat the file name to this, or have the file path hard coded into your html code as required.

PZ

abstractindia
Participating Frequently
December 7, 2010

Thanks pziecina !

Your suggestions are welcome I am looking forward to it. "Lookup" might not work but concatenating field values at runtime is definitely worth a try. Thanks !