Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# BC30456:';bindData';不是';购物车1.购物车';_C#_Asp.net_Vb.net - Fatal编程技术网

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

C# BC30456:';bindData';不是';购物车1.购物车';,c#,asp.net,vb.net,C#,Asp.net,Vb.net,类文件 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

类文件

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
现在,当我运行该页面时,我得到一个错误“BC30456:“bindData”不是“shoppingCart1.ShoppingCart”的成员。

问题是您的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文件

尝试以下操作:在页面顶部的代码隐藏处,在一行添加
Option Explicit On
,在另一行添加
Option Strict On
。这可能会突出代码中的一些问题区域。我怀疑在某个地方有另一个叫做shoppingcart的类,而不是你想要的那个。
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


}