Reference to non-shared member???

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005.

  1. 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
    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005
    #1
    1. Advertising

  2. 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:...
    > 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
    Eliyahu Goldin, Jan 27, 2005
    #2
    1. Advertising

  3. 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:...
    > > 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

    >
    >
    >
    =?Utf-8?B?VGltOjouLg==?=, Jan 27, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DJ Dev
    Replies:
    3
    Views:
    16,086
    Gandalf
    Feb 8, 2004
  2. tshad

    non-shared member errors

    tshad, May 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    3,610
    tshad
    May 18, 2005
  3. tshad
    Replies:
    11
    Views:
    798
    tshad
    May 27, 2005
  4. ce
    Replies:
    1
    Views:
    2,958
  5. bminder
    Replies:
    0
    Views:
    933
    bminder
    Jun 24, 2005
Loading...

Share This Page