|
Displaying Images through Access Database? Posted: 14 Nov 2003
Hi Rizwan!
You might be well aware that Access is a relational Database Software (Tables/relations based database),the results you want to achieve involve manipulating Objects (Images or Image files) so that you can render such Images in your ASP.NET pages.
There are various ways of achieving this: 1) You can Design your Access Database as an Object Relational database ( i.e tables storing Objects/Images rather than storing texts or numeric data). 2) You can design a normal Relational (text/ numeric based) Access database but just include a column which stores Object/Image identifiers (references images stored in a particular folder on your server).
Option 2 is much simpler and does not create waste disc space. Just create a table or a column for the images you want to display, each image record should include the exact filename of the image as an identifier. The location of the image at this level is not relevant. For example if u have an image filename called 'photo.jpg' this will be an identifier for that particular image.
Assuming you are using ADO.NET data access philosophy to render your access data in ASP.Net pages, what you need to do is just create a dataset for the data you want to display including the image Identifiers.
Consider the code below;
Dim sqlStr As String = "select * from tblImages" Dim cmd As new sqlCommand(sqlStr,cnnStr) cmd.CommandType = Command.Text Dim dtaImage as new sqlDataAdapter(cmd) Dim dts As new Dataset()
cnnStr.open() cmd.ExecuteNonquery(); dtaImage.Fill(dts,"tblImage") cnnStr.Close()
'To display the images in Asp.net 'Create a display control i.e some Label or Image control called 'lblImage' and the code would look as follows:
If dts.Tables("tblImage").rows.count >0 Then Dim imageName As String imageName = dts.Tables("tblImage").row(0).Item("fileName")
lblImage.Text = "\ImageFolder\" & imageName End If
The above code assumes that you have a column named 'fileName' in the table called 'tblImage' and that the dataset contains a single row. If the dataset (dts) contains many rows then use a For-Next loop to display each image depending on a particular constraint.
The 'ImageFolder' is the name of the folder on the current server where all your images are stored.
I hope this will give you a firm start.
Kind Rgds annasser
Nasser
|