Reference to non-shared member???

G

Guest

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("strConn"))
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
 
E

Eliyahu Goldin

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
 
G

Guest

Thanks...

Eliyahu Goldin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top