Wrox Programmer Forums
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2005, 11:30 PM
Registered User
 
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"





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.