DataSource series controls in ASP.net 2.0

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.