p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0

Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 19th, 2005, 12:30 AM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Working with a class

I have been racking my brain for days on this and have flipped through every ASP.Net book i have and have yet to come up with the correct way to do this! I am writing a custom class to make my code more manageable (obviously) but am having some difficulty.

Here is the code:
Code:
Public Class productImage

    Private intId as integer                                'Value for productID
    Private strImagePath as string                            'String Value for the Image Path

    Public Function GetImage(ByVal intPID as integer)
        Dim objConnection as New OleDbConnection                         'Dbase Connection
        Dim objCommand as New OleDbCommand                            'Dbase Command
        Dim objDataReader as OleDbDataReader                        'DataReader
        Dim strSQLQuery as string = ""                            'SQL Query

    objConnection = New System.Data.OLEDB.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("./dbase/schools.mdb") & ";"    )
    objConnection.open()

    strSQLQuery = "SELECT * from images where pid=" &intPID
    objCommand = New OleDbCommand(strSQLQuery, objConnection)
    objDataReader = objCommand.ExecuteReader()
        While objDataReader.Read
            'lblText.text ="You selected a " & objDataReader("prod_desc")
             SetImage("<img src=" & objDataReader("prod_image") &">")
        End While
        objConnection.Close()
        objDataReader.Close()
        objDataReader = Nothing
        objConnection = Nothing

    End Function

    Public Property SetImage() as string
        Get
            return strImagePath
        End Get
        Set(ByVal imageString as String)
            strImagepath = imageString
        End Set
    End Property        

    End Sub
End Class
Originaly I had the objConnection, DataReader, and command defined as private with all of my other variables because i was getting the error:

Reference to a non-shared member requires an object reference. on line 17 where i declare
Code:
objConnection = New System.Data.OLEDB.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("./dbase/schools.mdb") & ";"    )
I then moved the variables into the function thinking, for some reason, i couldnt access them. (Didnt make sense but I was working on process of elimination) again i got the same error. Then I thought that maybe I couldnt access the namespace so typed out the exact location of, for example, the OleDbConnection.

I also am getting an error where i try to call my property:
Code:
SetImage("<img src=" & objDataReader("prod_image") &">")
saying that to access a property i must either use or set its value.

Any ideas??

'Edit
I went back through the code and replaced Server.MapPath([location]) with the direct path to the database and this resolved the error, does anyone know why this would not work? I have verified that the path is correct ./dbase/schools.mdb

'Edit 2
I resolved this issue, apparently inside a class you must reference server.mappath() directly by using
Code:
httpContext.Current.Server.MapPath()
"There is nothing more honorable then doing a thing well"
__________________
\"There is nothing more honorable then doing a thing well\"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
class names in xslt not working chobo XSLT 2 January 13th, 2008 02:43 AM
EventUtil class not working in web server KelRegor BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 2 December 26th, 2007 09:50 AM
Property access from Class within Partial Class zoltac007 C# 2005 0 December 1st, 2006 01:01 AM
Regarding Class Library (.dll) from class file manish.sharma04 BOOK: Wrox's ASP.NET 2.0 Visual Web Developer 2005 Express Edition Starter ISBN: 978-0-7645-8807-5 1 March 3rd, 2006 07:32 AM
.syntax not working with class stephen_c_ Javascript 3 January 19th, 2005 07:21 AM



All times are GMT -4. The time now is 07:31 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc