views:

625

answers:

5

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

A: 

I'm new to asp.net c# and trying to follow the DAL tutorial, but keep getting the following error.

Compiler Error Message: CS0246: The type or namespace name 'ProductsTableAdapter' could not be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 17: protected void Page_Load(object sender, EventArgs e) Line 18: { Line 19: ProductsTableAdapter productsAdapter = new Line 20: ProductsTableAdapter(); Line 21: GridView1.DataSource = productsAdapter.GetProducts();

Source File: c:\Documents and Settings\dan\My Documents\Visual Studio 2010\WebSites\WebSite2\AllProducts.aspx.cs Line: 19

I've searched several forums for several hours and posted here becuse it was the most recent. Thanks for any help you can provide.

dan
A: 

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

Jaxin
A: 

I seem to be having the same issue. I have compiled it rebuilt it even rewrote every step. Once I had some code that started working but the "using NorthwindTableAdapters;" never worked even with that project. I get frustrated with Tutorials that don't work.

Has anyone figured out what the issue is? What the fix is?

Nathan Stanford
+1  A: 

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...

Janaitha Fernando
This was the solution for me as well when working with TableAdapters.
Dillie-O
A: 

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.

kjshaju