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-csWhen 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.aspxand sandy060583 pointed me towards this article:
http://www.codeguru.com/csharp/sample_chapter/article.php/c13471Now, so far I have tried these steps:
- Create an
App_Code
folder. - Right click the application folder and add a new
DataSet
- Within the
DataSet
Designer form I drag the table I want to type onto the form. - Next, I have been going to the aspx.cs page and add code to reference the new
DataSet
.
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