班级档案
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'的成员。 “
答案 0 :(得分:1)
问题是您的aspx页面和购物车类不在同一名称空间中。
您需要添加
Namespace shoppingCart1
(和结束命名空间)到您的shoppingcart类或从页面中删除命名空间。
答案 1 :(得分: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
}
答案 2 :(得分:0)
在Visual Studio 2005或2008中部署项目时经常发生此错误。 这个错误的主要原因是同一个项目的bin文件夹中存在重复的dll名称,你要做的就是从bin文件夹中删除未使用的dll文件