Minggu, 13 Februari 2011

ASP.NET 4.0 - Adding Typed DataSets

As with my post yesterday, I am working towards a real, enterprise-type application in terms of coding and file structure. After struggling with my approach based on the old ASP.NET article:

http://www.asp.net/data-access/tutorials/creating-a-data-access-layer-cs
When I tried adding the data in this case I kept getting errors when trying to reference the object in the DataAdapter provided by the .xsd. I posted on the ASP.NET forums:
http://forums.asp.net/t/1649988.aspx
and sandy060583 pointed me towards this article:
http://www.codeguru.com/csharp/sample_chapter/article.php/c13471
Now, so far I have tried these steps:
  1. Create an App_Code folder.
  2. Right click the application folder and add a new DataSet
  3. Within the DataSet Designer form I drag the table I want to type onto the form.
  4. Next, I have been going to the aspx.cs page and add code to reference the new DataSet.
So far I have found that the pattern for referencing these objects is as such. If I name a new DataSet CategoriesDataSet, then, the reference will look like this:
CategoriesDataSetTableAdapaters.CategoriesTableAdapter.
Taking this as the basis of my pattern I will start trying to reference my code this way:
[DataSetName]TableAdapters.[DataSetName]TableAdapter
Once I used this pattern, I was able to add code that actually worked:
// Add TableAdapter
CategoriesDataSetTableAdapters.CategoriesTableAdapter categoriesTableAdapter = new CategoriesDataSetTableAdapters.CategoriesTableAdapter();

// Fill DataTable
CategoriesDataSet.CategoriesDataTable categoriesDataTable = categoriesTableAdapter.GetData();

// Specify DataTable as GridView DataSource
GridView1.DataSource = categoriesDataTable;

// Bind DataTable to GridView
GridView1.DataBind();
Hopefully, I will be able to use them again in the future. I find every time I figure one of these things out, it changes the next time.

0 komentar:

Posting Komentar

 
Powered by Blogger