ASP. NET 2.0 has made great improvements in the data connection. The newly added datasource control makes it easier to connect to the database, many of them can write SQL statements and connect to databases through wizard settings. There are 6 DataSource controls in ASP. NET 2.0:
Sqldatasource control-data source control used to connect to the SQL database
Accessdatasource control-data source control used to connect to the access Database
ObjectDataSource control-data source control used to connect custom objects
DataSetDataSource control ----- controls that use XML files as dataset and perform relevant Processing
XmlDataSource control ----- this control loads Xml files and binds them to datagrid, datalist, and other controls.
SiteMapDataSource control ----- this control loads a pre-defined site layout file and binds it to the treenode tree control or Sitemappath control to facilitate the creation of site page navigation.
This article focuses on the ObjectDataSource control, DataSetDataSource control, and XmlDataSource control. For more information about sqldatasource control, see use ASP. NET 2.0 GridView control, this article introduces the use of sqldatasource control, and accessdatasource control, similar to sqldatasource control, but the connected database is access.
ObjectDataSource Control
This control binds the objects created by the user to the data control, such as the datagrid and gridview. The following is an example. In visual studio 2005 beta 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],