类文件中的一员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'的成员 “
我添加了命名空间到类文件....没有运气。 – 2012-01-11 19:21:43
试试这个:在页面代码的顶部,在一行上添加Option Explicit On,在另一行添加Option Strict On。这可以突出代码中的一些有问题的部分。我怀疑还有另一个叫做shoppingcart的类,它正在被拾起而不是你想要的那个。 – 2012-01-11 19:48:34