2012-01-11 31 views
0

类文件中的一员BC30456: 'bindData' 不是 'shoppingCart1.ShoppingCart'

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

回答

1

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

你要么需要

Namespace shoppingCart1 

(和最终命名空间)添加到您的购物车类或删除页面的命名空间。

+0

我添加了命名空间到类文件....没有运气。 – 2012-01-11 19:21:43

+0

试试这个:在页面代码的顶部,在一行上添加Option Explicit On,在另一行添加Option Strict On。这可以突出代码中的一些有问题的部分。我怀疑还有另一个叫做shoppingcart的类,它正在被拾起而不是你想要的那个。 – 2012-01-11 19:48:34

0

检查班级的等级。在你的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 


} 
0

此错误频繁发生,同时部署在Visual Studio 2005年或2008年一期工程 此错误的原因主要是重复的DLL名称的同一项目的bin文件夹中的所有脑干,alll什么你必须做的是从bin文件夹中删除未使用的dll文件

相关问题