【问题标题】:BC30456: 'bindData' is not a member of 'shoppingCart1.ShoppingCart'BC30456:“bindData”不是“shoppingCart1.ShoppingCart”的成员
【发布时间】:2012-01-11 19:10:38
【问题描述】:

类文件

Public Function bindData() As String
        Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
        'Dim objDA As SqlDataAdapter
        Dim myRow As SqlDataReader
        Dim comd As New SqlCommand("SELECT * FROM products", con)
        con.Open()
        myRow = comd.ExecuteReader()
        Dim strRowGen As String = ""
        While myRow.Read()
            strRowGen = strRowGen & "<TR>"
            strRowGen = strRowGen & "<TD>" & myRow.GetValue(0) & "</TD>"
            strRowGen = strRowGen & "<TD>" & myRow.GetValue(1) & "</TD>"
            strRowGen = strRowGen & "<TD>" & myRow.GetValue(2) & "</TD>"
            strRowGen = strRowGen & "<TD><a href='#' onclick=""javascript:document.Form1.action='ShoppingPage.aspx?Actn=Add&itemId=" & myRow.GetValue(0) & "';document.Form1.submit();"">Add To Cart</TD>"
            strRowGen = strRowGen & "</TR>"
            'cellshoping.InnerHtml = strRowGen
        End While
        Return strRowGen
    End Function

ASPX 代码隐藏

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    'Load data by calling function bindData()
            Dim sCart = New ShoppingCart
            If Not Page.IsPostBack Then

                cellshoping.InnerHtml = sCart.bindData()
            End If
End Sub

现在,当我运行该页面时,我收到此错误“BC30456:‘bindData’不是‘shoppingCart1.ShoppingCart’的成员。 "

【问题讨论】:

    标签: c# asp.net vb.net


    【解决方案1】:

    问题是您的 aspx 页面和您的购物车类不在同一个命名空间中。

    你要么需要添加

    Namespace shoppingCart1
    

    (和结束命名空间)添加到您的购物车类或从页面中删除命名空间。

    【讨论】:

    • 试试这个:在你的页面顶部代码后面,在一行添加Option Explicit On,在另一行添加Option Strict On。这可能会突出代码中的一些问题区域。我怀疑在某个地方还有另一个名为 shoppingcart 的类正在被取走,而不是你想要的。
    【解决方案2】:

    检查类的层次结构。在您的 cs 文件中,如果它是纯类文件,而不是后面的代码。你必须有

    using System;
    
    namespace yourNameSpace
    {
      public class yourClassName
      {
         public function binddata()
         {
                // your logic
         }
       }
    }
    
    
    aspx.cs/vb
    
    partial class aspxClass
    {
       dim yourObjectName as new yourClassName()
       //do whatever with the object
    
    
    }
    

    【讨论】:

      【解决方案3】:

      在 Visual Studio 2005 或 2008 中部署项目时经常发生此错误。 此错误的主要原因是同一项目的 bin 文件夹中存在重复的 dll 名称,您需要做的就是从 bin 文件夹中删除未使用的 dll 文件

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多