asp.net 2.0, in which the data connection has made great improvements, the new DataSource series of controls to make the connection between the database easier, many can through the wizard-style settings to complete the writing of SQL statements and database connections. The DataSource series controls in ASP.net 2.0 total 6 species, respectively:
SqlDataSource Control----Data source control used to connect to a SQL database
AccessDataSource Control----Data source control used to connect to an Access database
The ObjectDataSource control----The data source control used to connect the custom object
Datasetdatasource Control-----A control that makes an XML file a dataset and does related processing
The XmlDataSource Control-----The control to load the XML file and bind to controls such as the DataGrid, DataList, and so on
The SiteMapDataSource control-----The control to load a predefined site layout file and then bind it to the TreeNode tree control or SiteMapPath control to make the site's page navigation easier.
The following figure shows the six kinds of controls for datasource in the Vs.net-1 Express Beta:
In this article, you will focus on ObjectDataSource controls, Datasetdatasource controls, and XmlDataSource controls, and SqlDataSource controls, refer to the Use ASP.net 2.0 The GridView control in, which describes how the SqlDataSource control is used, and the AccessDataSource control is similar to the SqlDataSource control, except that the connected database is access.
ObjectDataSource Control
The control that binds the objects created by the user to the data control, such as binding to Datagrid,gridview. For example, in Visual Studio 1, create a new site and add a new class named Products:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Public Class Products
Public Function getProducts() As DataSet
Dim conn As New SqlConnection("Server=(local);Integrated Security=True;Database=Northwind;Persist
Security Info=True")
Dim adapter As New SqlDataAdapter("SELECT [ProductID], [ProductName], [SupplierID], [CategoryID],
[QuantityPerUnit], [UnitPrice] FROM [Products]", conn)
Dim ds As New DataSet
adapter.Fill(ds, "Products")
Return ds
End Function
End Class
The Product class contains the GetProducts method, which returns all the products in the Northwind database and returns as a dataset. With the ObjectDataSource control, you can bind a custom class to a data control, but simply drag the Ojectdatasource control into the design form, and then click the ' Configure Data Source ... ' link, In the pop-up form (pictured below), select the class you want to bind, and then select the Product class.
In the next step, select the related method in which class you want to bind, as shown in the following figure: