2011-05-03 80 views
0

現在,當我運行一個用VB.NET編寫的ASPX頁面時,出現上述錯誤。所以我試着按照下面的解決方案: http://msdn.microsoft.com/en-us/library/zwwhc0d0(v=vs.80).aspx對非共享成員的引用需要一個對象引用

上述鏈接似乎很有前途,因爲它似乎完全描述我的問題。不過,我得到了這個解決方案如下錯誤:

Compiler Error Message: BC30456: 'GlobalF2' is not a member of 'GlobalFunctions' Line 88:
DSProductData = GlobalFunctions.GlobalF2.ComplaintTrendingDrillDown3p(FirstMonthDate, LastMonthDate, TheLevel, ProductGroup, TheCategory, ListNumber)

這裏是我修改的源代碼,造成這個錯誤,而是基於關閉的邁克·史密斯的解決方案:

Namespace GlobalFunctions 
    Public Class 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 

    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 

我認爲邁克·史密斯是正確的關於不使用共享,因爲我認爲這導致了這個問題。然而,我是VB.NET的新手,我不知道如何將一個實例聲明爲一個對象變量,然後通過變量名引用這個實例。你能幫我嗎?

好的,你的解決方案對我來說很好。我想確保我正確實施它,但是。你能和我比較一下嗎?

現在我得到了同樣的錯誤,我最初...也許它覆蓋表中的數據?

  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 

和錯誤:

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

出錯行:

If pException("QXP_SHORT_DESC") = TheCategory Then

回答

1

不能暗淡的方法外的類的實例可以使用

public GlobalF2 As New GlobalF 
編輯

我不確定你正在嘗試做什麼,但把所有無關的代碼拉出來。

類文件

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 

主文件

Imports System.IO 
Module Module1 


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

End Module 
+0

那怎麼還能怎麼解決這個問題?這就是邁克史密斯在他的代碼中所做的,列在上面的URL中。 – salvationishere 2011-05-03 19:15:03

+0

嘿,重新運行,謝謝你的幫助!你能檢查我的更新說明嗎? – salvationishere 2011-05-03 22:47:42

相關問題