BC30456:';bindData';不是';购物车1.购物车';

本文关键字:购物车 不是 bindData BC30456 | 更新日期: 2023-09-27 18:20:06

类文件

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'的成员。"

BC30456:';bindData';不是';购物车1.购物车';

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

你要么需要添加

Namespace shoppingCart1

(和结束名称空间)添加到您的shoppingcart类,或者从页面中删除该名称空间。

检查类的继承结构。在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

}

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