Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 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 10th, 2004, 04:27 PM
Authorized User
 
Join Date: Aug 2004
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Writable Properties Using the set Accesso

I have a simple class that I am writing using properties. When I attempt to access the value of one of the properties I receive this error:

An object reference is required for the nonstatic field, method, or property 'RC2003.member.mLname'

Here is a code snippet:

public class member
        {
private string mFname, mLname;

        public string LastName
        {
            get {return mLname;}
            set {mLname = value;}
        }

public static void UpdateMember(int ID)
{

// SQL STUFF
            objCmd.Parameters["@mFname"].Value = mFname;
}
}
}

I also tried accessing the property LastName. I'm not entierly sure that I am using the propeties the correct way. Is this right? What am I missing?

Thank you,

-- shawn

 
Old August 12th, 2004, 05:00 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

The error says it all.

You have a static function. The property is not static. The two don't play together. You much have an instance of your class in order to have an instance of mFname for the line of code in UpdateMember to use. You need to pass all the external values as arguments into a static method or the method must use static or constant values. The method can not use instance fields.





Similar Threads
Thread Thread Starter Forum Replies Last Post
set page properties by code. Komila ASP.NET 1.0 and 1.1 Basics 0 July 6th, 2006 05:36 AM
How to set the print properties of excel with vb6 wyq1234 Visual Basic 2005 Basics 0 July 5th, 2006 10:09 AM
Set AdoDc properties at run time Psionman Pro VB Databases 2 November 10th, 2004 10:07 AM
How to set (right click)properties for an object mpkrishna Classic ASP Components 1 August 24th, 2003 01:30 AM





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