Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Forums : .NET : ADO.NET : Displaying Images through Access Database? Signup · Login
Author Thread
Displaying Images through Access Database?
Posted in tutorial: 2 Ways of Displaying Data from a SQL Server Database using ASP.NET
·  snips
User
Joined: 7 Jan 2003
Total Posts: 4
Displaying Images through Access Database?
Posted: 7 Jan 2003
Hello i m making a site using ASP.NET using VB.NET
and i m getting problem in displaying images through Access database .. i dont know how i can do that... i want full detail on it .. even the code also ..
i shall be thankful to u
early reply will be appreciated..
Rizwan

Rizwan Haider
·  annasser
User
Joined: 14 Nov 2003
Total Posts: 1
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

Users Who Have Visited This Thread In Last 24 Hours
4 Visitors

Login
UserName Or Email Address:       Password:       Auto-Login:    
· Create New User Account
· Send Forgotten Password by Email
 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.