I have class, which returns dataTable to populate my list box on some other
pages:
public class dataClass
{
private Int16 _lvlRights=1
public static DataTable dtAdv()
{
if (_lvlRights == 1)
{
//my code......
}
}
}
I get an error:
Error 1 An object reference is required for the nonstatic field, method, or
property 'dataClass._lvl Rights'
If I remove static keyword from dtAdv method than it works, but than I can't
call my class from other pages:
lstBox.DataSour ce=dataClass.dt Adv()
How can I use variable _lvlRights in my static methods?
Regards,S 2 8579
Hi Simon,
You must make _lvlRights static.
private static Int16 _lvlRights = 1;
On Mon, 28 Aug 2006 10:10:22 +0200, simonZ
<si*********@st udio-moderna.comwrot e:
I have class, which returns dataTable to populate my list box on some
other
pages:
public class dataClass
{
private Int16 _lvlRights=1
public static DataTable dtAdv()
{
if (_lvlRights == 1)
{
//my code......
}
}
}
I get an error:
Error 1 An object reference is required for the nonstatic field, method,
or
property 'dataClass._lvl Rights'
If I remove static keyword from dtAdv method than it works, but than I
can't
call my class from other pages:
lstBox.DataSour ce=dataClass.dt Adv()
How can I use variable _lvlRights in my static methods?
Regards,S
--
Happy Coding!
Morten Wennevik [C# MVP]
Hi ,
You can either make lvlRights static or remove the static from the method.
If you make static lvlRights you have to be careful with concurrency in case
that variable could be changed from an external property.
Additionally you could make your class a singleton.
Another route is declare your class as static (if you are using 2.0 ) this
will prevent you from declaring any instance member
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"simonZ" <si*********@st udio-moderna.comwrot e in message
news:eP******** ******@TK2MSFTN GP06.phx.gbl...
>I have class, which returns dataTable to populate my list box on some other pages:
public class dataClass
{
private Int16 _lvlRights=1
public static DataTable dtAdv()
{
if (_lvlRights == 1)
{
//my code......
}
}
}
I get an error:
Error 1 An object reference is required for the nonstatic field, method,
or property 'dataClass._lvl Rights'
If I remove static keyword from dtAdv method than it works, but than I
can't call my class from other pages:
lstBox.DataSour ce=dataClass.dt Adv()
How can I use variable _lvlRights in my static methods?
Regards,S
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: muralidharan |
last post by:
WebForm1.aspx Code:
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI"
Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView
id="TreeView1" Height="520" AutoPostBackOnNodeMove="false"
DragAndDropEnabled="true"
NodeEditingEnabled="False" KeyboardEnabled="true"
CssClass="TreeView" NodeCssClass="TreeNode"
SelectedNodeCssClass="SelectedTreeNode"
HoverNodeCssClass="HoverTreeNode" NodeEditCssClass="NodeEdit"
|
by: Bucko |
last post by:
Hi guys,
this may be an easy for someone...
I have a situation like below. The "str" string variable (and any other
variable that VS.net declares normally in this space) can be used fine
in the Page_Load function, but not my own function, "datareaderconvert"
Anyone know why? Here's what it looks like:
|
by: William Mild |
last post by:
I must be getting brain fried. I can't see the error.
Create a new web form with the following code begind:
Public Class test
Inherits System.Web.UI.Page
Public Class ReportCardData
Public Structure Attend
Dim DaysTardy As Double
|
by: Remulac |
last post by:
Hello,
I'm trying to get the value out of a dropdown list box and
assign it to a variable. When I click on the list box, I
invoke this line of code. I get the error, "Object
reference not set to an instance of an object".
The same list box is referenced successfully in the form
load. Does anyone know what might cause this problem?
|
by: ST |
last post by:
Hello everyone, Can anyone help me with this error above when I debug my web
app project in vstudio.net?? I can't figure it out! It was working fine for
months, and now all of a sudden it's not!!
This is the error:
biopsy.searchsubject.btnSubject_Click(Object Sender, EventArgs e) in
C:\INetPub\WWWRoot\biopsy\searchsubject.aspx.vb:198
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
| |
by: SAL |
last post by:
I am getting the following ERROR in my WebApp on line 30:
Server Error in '/TestWebApp' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.
|
by: Don |
last post by:
I'm getting the following exception displayed in the task list at design
time for my project:
"Code generation for property 'Controls' failed. Error was: 'Object
reference not set to an instance of an object.'"
I've traced the problem to a custom control I created that inherits from
Inherits System.Windows.Forms.TextBox. In this custom control, I have
two constructors. I'm not sure why I created the second constructor --
it was so...
|
by: cppquester |
last post by:
I have a data set
MMSDataAccess
with:
public partial class MMSDataSet : System.Data.DataSet {
...
private TB_ACTHEATDATADataTable tableTB_ACTHEATDATA;
...
|
by: livmacca |
last post by:
Hi,
I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work:
==================ERROR==================================
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the...
|
by: mrcw |
last post by:
Hi
I've added a textbox called tbAccel0 to a form. It shows up on the form with the correct name, but when I look at the code a red squigly line appears under tbAccel0 and an error appears in the error list saying
An object reference is required for the non-static field, method, or property
I don't understand why. Surely an object reference was added when I added the textbox to the form.
This is the only time this has happened, if...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |