473,472 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reference to non-shared member???

Can someone please tell me why I get the following error in my code and how I
fix it!

Error:
Reference to a non-shared member requires an object reference.

I keep getting this error on

objParam1.Value = User.Identity.Name

Thanks

Code..
Public Shared Function GetOfficeName() As String
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("UserDetails", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objParam1 As SqlParameter
objParam1 = cmd.Parameters.Add("@UserName", SqlDbType.Char)
objParam1.Direction = ParameterDirection.Input
objParam1.Value = User.Identity.Name

Dim myReader As SqlDataReader = cmd.ExecuteReader()
While myReader.Read()
If User.Identity.Name <> "" Then
Return myReader("offName")
End If
End While
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
Myconn.Close()

End Function
Nov 19 '05 #1
2 1430
A shared (static) method can't refered a non-shared member which User is.

Either Remove Shared from the function definition, or use
HttpContext.Current.User.

Eliyahu

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:0F**********************************@microsof t.com...
Can someone please tell me why I get the following error in my code and how I fix it!

Error:
Reference to a non-shared member requires an object reference.

I keep getting this error on

objParam1.Value = User.Identity.Name

Thanks

Code..
Public Shared Function GetOfficeName() As String
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("UserDetails", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objParam1 As SqlParameter
objParam1 = cmd.Parameters.Add("@UserName", SqlDbType.Char)
objParam1.Direction = ParameterDirection.Input
objParam1.Value = User.Identity.Name

Dim myReader As SqlDataReader = cmd.ExecuteReader()
While myReader.Read()
If User.Identity.Name <> "" Then
Return myReader("offName")
End If
End While
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
Myconn.Close()

End Function

Nov 19 '05 #2
Thanks...

"Eliyahu Goldin" wrote:
A shared (static) method can't refered a non-shared member which User is.

Either Remove Shared from the function definition, or use
HttpContext.Current.User.

Eliyahu

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:0F**********************************@microsof t.com...
Can someone please tell me why I get the following error in my code and

how I
fix it!

Error:
Reference to a non-shared member requires an object reference.

I keep getting this error on

objParam1.Value = User.Identity.Name

Thanks

Code..
Public Shared Function GetOfficeName() As String
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("UserDetails", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

Dim objParam1 As SqlParameter
objParam1 = cmd.Parameters.Add("@UserName", SqlDbType.Char)
objParam1.Direction = ParameterDirection.Input
objParam1.Value = User.Identity.Name

Dim myReader As SqlDataReader = cmd.ExecuteReader()
While myReader.Read()
If User.Identity.Name <> "" Then
Return myReader("offName")
End If
End While
' always call Close when done reading.
myReader.Close()
' Close the connection when done with it.
Myconn.Close()

End Function


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ded' | last post by:
Hello ! I've read in a magazine "reference parameter in operator= must be const, because in C++, temporary objects are const" and then my operator would not work with temporary objets. But,...
5
by: klaus triendl | last post by:
hi, recently i discovered a memory leak in our code; after some investigation i could reduce it to the following problem: return objects of functions are handled as temporary objects, hence...
8
by: SpOiLeR | last post by:
Hello! I have a matrix class like this: class MyObject; // MyMatrix is contains MyObjects class MyMatrix { public: ...
6
by: amparikh | last post by:
I know this is something fundamental and I ought to have known it, but somehow this seems to be confusing me a lot. Fundamentally, rvalues and/or temporaries can be bound only to constant...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
27
by: David W | last post by:
I'm almost tearing my hair out. A colleague claimed that a null reference can exist, like this: void f( int& p ) { printf( "%d\n", p ); } int main (int argc, char *argv) {
3
by: George2 | last post by:
Hello everyone, I am debugging MSDN code from, http://msdn2.microsoft.com/en-us/library/0eestyah(VS.80).aspx here is my output, 1>main.cpp
5
by: George2 | last post by:
Hello everyone, This is my understanding of non-const reference, const reference and their relationships with lvalue/rvalue. Please help to review whether it is correct and feel free to...
13
by: asm23 | last post by:
Hi,I need some help to clarify the warning "initial value of reference to non-const must be an lvalue". I'm searching in this groups to find someone has the same situation like me. I found in...
5
by: Daniel Oberhoff | last post by:
Hi, Can someone more proficient in the details of the c++ type system please tell me how I can instantiate the for constesses of references that I think should be possible: 1. non-constant...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
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...
0
agi2029
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,...
1
isladogs
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.