开发者

Reference to a non-shared member requires an object reference

I am getting the above error now when I run one of my ASPX pages, written in VB.NET. So I tried following the solution at: http://msdn.microsoft.com/en-us/library/zwwhc0d0(v=vs.80).aspx

The above link seemed promising, cause it seemed to describe my problem exactly. However, I got the following error from this solution:

Compiler Error Message: BC30456: 'GlobalF2' is not a member of 'GlobalFunctions' Line 88:

DSProductData = GlobalFunctions.GlobalF2.ComplaintTrendingDrillDown3p(FirstMonthDate, LastMonthDate, TheLevel, ProductGroup, TheCategory, ListNumber)

And here is my modified source code causing this error, but based off of Mike Smith's solution:

Namespace GlobalFunctions
    Public Class GlobalF
        Public Function ComplaintTrendingDrillDown3p(ByVal FirstMont开发者_如何转开发h As DateTime, ByVal LastMonth As DateTime, ByVal rowLevel As Integer, ByVal productGroup As String, ByVal category As String, ByVal ListNumber As String) As DataSet
            Dim DSPageData As New System.Data.DataSet
            Dim param(5) As SqlClient.SqlParameter

            param(0) = New SqlParameter("@FirstMonthDate", SqlDbType.DateTime)
            param(0).Value = FirstMonth
            param(1) = New SqlParameter("@LastMonthDate", SqlDbType.DateTime)
            param(1).Value = LastMonth
            param(2) = New SqlParameter("@TheLevel", SqlDbType.Int)
            param(2).Value = rowLevel
            param(3) = New SqlParameter("@ProductGroup", SqlDbType.Varchar)
            param(3).Value = productGroup
            param(4) = New SqlParameter("@TheCategory", SqlDbType.Varchar)
            param(4).Value = category
            param(5) = New SqlParameter("@ListNumber", SqlDbType.Varchar)
            param(5).Value = ListNumber

            ''# A Using block will ensure the .Dispose() method is called for these variables, even if an exception is thrown 
            ''# This is IMPORTANT - not disposing your connections properly can result in an unrespsonsive database 
            Using conn As New SQLConnection(ConfigurationSettings.AppSettings("AMDMetricsDevConnectionString")), _
           cmd As New SQLCommand("ComplaintTrendingDrillDown3p", conn), _
            da As New SQLDataAdapter(cmd)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddRange(param)

                da.Fill(DSPageData)
            End Using

            Return DSPageData
        End Function
    End Class

    Public Class CallingClass
        Dim GlobalF2 As New GlobalF
        Public Function ComplaintTrendingDrillDown3p(ByVal FirstMonth As DateTime, ByVal LastMonth As DateTime, ByVal rowLevel As Integer, ByVal productGroup As String, ByVal category As String, ByVal ListNumber As String) As DataSet
            Dim DSPageData As New System.Data.DataSet
            Dim param(5) As SqlClient.SqlParameter

            param(0) = New SqlParameter("@FirstMonthDate", SqlDbType.DateTime)
            param(0).Value = FirstMonth
            param(1) = New SqlParameter("@LastMonthDate", SqlDbType.DateTime)
            param(1).Value = LastMonth
            param(2) = New SqlParameter("@TheLevel", SqlDbType.Int)
            param(2).Value = rowLevel
            param(3) = New SqlParameter("@ProductGroup", SqlDbType.Varchar)
            param(3).Value = productGroup
            param(4) = New SqlParameter("@TheCategory", SqlDbType.Varchar)
            param(4).Value = category
            param(5) = New SqlParameter("@ListNumber", SqlDbType.Varchar)
            param(5).Value = ListNumber

            ''# A Using block will ensure the .Dispose() method is called for these variables, even if an exception is thrown 
            ''# This is IMPORTANT - not disposing your connections properly can result in an unrespsonsive database 
            Using conn As New SQLConnection(ConfigurationSettings.AppSettings("AMDMetricsDevConnectionString")), _
           cmd As New SQLCommand("ComplaintTrendingDrillDown3p", conn), _
            da As New SQLDataAdapter(cmd)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddRange(param)

                da.Fill(DSPageData)
            End Using

            Return DSPageData
        End Function
    End Class

End Namespace

I think Mike Smith is correct about not using Shared, cause I think that caused this problem. However, I am a newbie at VB.NET and I'm not sure how else to declare an instance as an object variable and then reference this instance by variable name. Can you help?

OK, ur solution looked very good to me. I want to make sure I implemented it correctly though. Can you compare mine to urs?

Now I get the same error I had initially...Maybe it's overwriting data in the table?

            Dim gf As New GlobalFunctions.CallingClass
            DSProductData = gf.GlobalF2.ComplaintTrendingDrillDown3p(FirstMonthDate, LastMonthDate, TheLevel, ProductGroup, TheCategory, ListNumber)
...
    Public Class CallingClass
        Public GlobalF2 As New GlobalF
        'Public Function CallingClass(ByVal FirstMonth As DateTime, ByVal LastMonth As DateTime, ByVal rowLevel As Integer, ByVal productGroup As String, ByVal category As String, ByVal ListNumber As String)
        '    Dim cc_new As New CallingClass()
        'End Function

        Public Function ComplaintTrendingDrillDown3p(ByVal FirstMonth As DateTime, ByVal LastMonth As DateTime, ByVal rowLevel As Integer, ByVal productGroup As String, ByVal category As String, ByVal ListNumber As String) As DataSet
            Dim DSPageData As New System.Data.DataSet
            Dim param(5) As SqlClient.SqlParameter

            param(0) = New SqlParameter("@FirstMonthDate", SqlDbType.DateTime)
            param(0).Value = FirstMonth
            param(1) = New SqlParameter("@LastMonthDate", SqlDbType.DateTime)
            param(1).Value = LastMonth
            param(2) = New SqlParameter("@TheLevel", SqlDbType.Int)
            param(2).Value = rowLevel
            param(3) = New SqlParameter("@ProductGroup", SqlDbType.Varchar)
            param(3).Value = productGroup
            param(4) = New SqlParameter("@TheCategory", SqlDbType.Varchar)
            param(4).Value = category
            param(5) = New SqlParameter("@ListNumber", SqlDbType.Varchar)
            param(5).Value = ListNumber

            ''# A Using block will ensure the .Dispose() method is called for these variables, even if an exception is thrown 
            ''# This is IMPORTANT - not disposing your connections properly can result in an unrespsonsive database 
            Using conn As New SQLConnection(ConfigurationSettings.AppSettings("AMDMetricsDevConnectionString")), _
           cmd As New SQLCommand("ComplaintTrendingDrillDown3p", conn), _
            da As New SQLDataAdapter(cmd)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddRange(param)

                da.Fill(DSPageData)
            End Using

            Return DSPageData
        End Function
    End Class

And the error:

System.ArgumentException: Column 'QXP_SHORT_DESC' does not belong to table Table.

The offending line:

If pException("QXP_SHORT_DESC") = TheCategory Then


You can't dim an instance of a class outside a method you can use

public GlobalF2 As New GlobalF

EDIT


I'm not sure exactly what you are attempting to do but pulling all of the extraneous code out.

Class File

Namespace GlobalFunctions

    Public Class GlobalF
        Public Sub DoSomthing()
            Console.WriteLine("hi")
        End Sub

    End Class

    Public Class CallingClass
        Public GlobalF2 As New GlobalF
        Public x As Int16 = 3
    End Class
End Namespace

Main File

Imports System.IO
Module Module1


    Public Sub Main()
        Dim gf As New GlobalFunctions.CallingClass
        gf.GlobalF2.DoSomthing()
    End Sub

End Module
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜