Monday, July 2, 2007

Accessing Typed Datasets

How to access Typed DataSet from C# .NET code ?

Dim productsAdapter As New NorthwindTableAdapters.ProductsTableAdapter()

Dim products as Northwind.ProductsDataTable


products = productsAdapter.GetProducts()


For Each productRow As Northwind.ProductsRow In products

Response.Write("Product: " & productRow.ProductName & "<br />")

Next


Each object used in this example is also strongly-typed, allowing Visual Studio to provide IntelliSense and compile-time type checking. And best of all the DataTables returned by the TableAdapter can be bound to ASP.NET data Web controls, such as the GridView, DetailsView, DropDownList, CheckBoxList, and several others.


Parameterized Methods in Typed DataSet based Data Access Layer.

It's almost same as the normal select all query.
Just go to DataSet designer and Right-click the TableAdapter section.
Click to "Add Query…".

You can preferably select Stored Procedure or Ad-Hoc Query.

In the next dialog screen, specify the query or select the procedure.

Now just rename the Fill and Get methods as per your preference and the methods are ready to test as soon as you finish the dialog.

Right-click on the table adapter and choose preview data to enter parameter values and see the results.


Anyhow, this is the best article that I have found on Typed Datasets…everything you need to know about typed datasets creation and using them.

No comments:

 
Dotster Domain Registration Special Offer