ASP.net DAL 数据集和表适配器不在命名空间中 - Northwind 教程

发布于 2024-08-27 06:35:09 字数 1071 浏览 5 评论 0原文

我一直在尝试浏览“创建数据访问层”教程,发现 http://www.asp.net/learn/data-access/tutorial-01-cs.aspx

我创建数据库连接,创建类型化数据集和表适配器,指定sql等 当我将代码添加到表示层(在本例中为名为 AllProducts.aspx的

页面)时,我无法找到 NorthwindTableAdapters.ProductsTableAdapter 类。我尝试导入 NorthwindTableAdapters 命名空间,但它没有显示。查看解决方案资源管理器类视图确认存在 Northwind 类,但不是我正在查找的命名空间。

我已经尝试了几个在线教程,它们的步骤基本相同,并且得到了相同的结果。

谁能推动我朝正确的方向前进?

我收到错误:导入“NorthwindTableAdapters”中指定的命名空间或类型不包含任何公共成员或无法找到。确保命名空间或类型已定义并且至少包含一个公共成员。

我想我可能需要添加一个引用,或者他们可能正在创建一个单独的类并将其导入到他们的主项目中。如果是这样的话,教程就不会提到这一点。

SupplyrsTest2.aspx.vb:

    Imports NorthwindTableAdapters 

   Partial Class SuppliersTest2

   Inherits System.Web.UI.Page



   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



    Dim suppliersAdapter As New SuppliersTableAdapter



    GridView1.DataSource = suppliersAdapter.GetAllSuppliers()

    GridView1.DataBind()



End Sub

结束类

I've been attempting to walk through the "Creating a Data Access Layer" tutorial found http://www.asp.net/learn/data-access/tutorial-01-cs.aspx

I create the DB connection, create the typed dataset and table adapter, specify the sql, etc.

When I add the code to the presentation layer (in this case a page called AllProducts.aspx) I am unable to find the NorthwindTableAdapters.ProductsTableAdapter class. I tried to import the NorthwindTableAdapters namespace, but it is not showing up. Looking in the solution explorer Class View confirms that there is a Northwind class, but not the namespace I'm looking for.

I've tried several online tutorials that all have essentially the same steps, and I'm getting the same results.

Can anyone give me a push in the right direction?

I'm getting error: Namespace or type specified in the Imports 'NorthwindTableAdapters' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member.

I think I might need to add a reference OR they may be creating a separate class and importing it into their main project. If that's the case, the tutorials do not mention this.

SuppliersTest2.aspx.vb:

    Imports NorthwindTableAdapters 

   Partial Class SuppliersTest2

   Inherits System.Web.UI.Page



   Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



    Dim suppliersAdapter As New SuppliersTableAdapter



    GridView1.DataSource = suppliersAdapter.GetAllSuppliers()

    GridView1.DataBind()



End Sub

End Class

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

绮筵 2024-09-03 06:35:09

我也遇到了同样的问题,最后找到了解决方案。尝试以下操作;
1)右键单击您的数据集并选择属性
2) 在数据集属性下,为 Prifix 属性设置名称。
3) 调试您的应用程序。
4)在您的应用程序(C#.net)中将名称空间导入为
using DALexample.MyTableAdapters;

DALexample 是您的项目名称...

I also had the same problem and finally found the solution. try followings;
1) Right click on your DataSet and select properties
2) Under the dataset properties, set a name for Prifix property.
3) debug your application.
4) in your application(C#.net) import the namesapce as
using DALexample.MyTableAdapters;

DALexample is your project name...

寂寞笑我太脆弱 2024-09-03 06:35:09

您需要在创建 xsd 文件之后、添加代码以使用表适配器之前编译代码。

因此,查看本教程,在创建 AllProducts.aspx 之前,您需要构建代码。这将自动生成 NorthwindTableAdapters 命名空间及其背后的代码,您将需要继续本教程

You need to compile the code after creating the xsd file, but before you add code to the use the table adapter.

So, looking at the tutorial, before you create the AllProducts.aspx, you need to build the code. This will auto-generate the NorthwindTableAdapters namespace and the code behind it you will need to continue on with the tutorial

爱的那么颓废 2024-09-03 06:35:09

由于某种原因,您的网络项目肯定已被重复。创建一个全新的 Web 项目并将所有当前代码复制到其中。然后尝试跑步。它会起作用的。

Your web project must have been duplicated for some reson. Create an entirely new web project and copy all your current code to it. Then try to run. it will work.

北风几吹夏 2024-09-03 06:35:09

我也被这个问题难住了 - 问题很可能是您使用“新建项目”->“ASP.NET Web 应用程序”创建的项目。应用程序项目与网站项目不同。使用新建网站->ASP.NET 网站创建项目。然后将所有教程文件放入解决方案资源管理器中的根文件夹中,覆盖所有文件。

当我尝试重新创建 DataSet 时,我注意到出现了问题,并且向导没有自动启动要求我将其放入 App_Code 文件夹。 App_Code 文件夹必须特定于 ASP.NET 网站而不是应用程序。

I got stumped on this for a bit also - the problem is likely that you created the project using New Project->ASP.NET Web Application. An Application project isn't the same thing as a Web Site project. Create a project using New Web Site->ASP.NET Web Site. Then drop all tutorial files into the root folder in Solution Explorer overwriting all.

I noticed something was up when I tried to recreate the DataSet and the wizard didn't autostart asking me to put it the App_Code folder. The App_Code folder must be specific to ASP.NET Web Sites and not Applications.

枉心 2024-09-03 06:35:09

转到 web.config 文件,在“页面 - 命名空间”下,查看是否有clear命令,尝试删除clear命令:

<pages styleSheetTheme="DataWebControls">
  <namespaces>
    <clear/>

对我来说,不需要创建一个新网站并复制所有源文件(除了web.xml)。配置文件),我只能备份我的 web.config 文件,然后删除 web.config 文件,然后去添加新项目并添加一个新的 web.config 文件,该文件创建了一个新文件我需要的默认值,然后我只需将自定义条目从旧的 web.config 文件复制到新的文件中,就可以了。

Go to the web.config file and under Pages - namespaces, see if there is a clear command, try removing the clear command:

<pages styleSheetTheme="DataWebControls">
  <namespaces>
    <clear/>

For me, instead of needing to create a new website and copying all of the source files (except the web.config file) to it, I was just able to make a backup of my web.config file, then delete the web.config file, then go to add new item and add a new web.config file, that created a new file with the defaults I needed, then I just copyed the custom entries from my old web.config file to the new one, and I was good to go.

牛↙奶布丁 2024-09-03 06:35:09

我也曾为此苦苦挣扎,但通过关闭 Visual Studio,重新打开我的项目,最后构建解决方案(CTRL+SHIFT+B)解决了这个问题。

I was also struggling with this but solved it by closing down Visual Studio, reopening my project, and finally building the solution (CTRL+SHIFT+B).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文