asp.net 2.0 (C #) (8)

Source: Internet
Author: User

Introduced

There are several new data source controls in ASP.net 2.0, such as SqlDataSource, ObjectDataSource, XmlDataSource, AccessDataSource, and SiteMapDataSource. All of them can be used to retrieve data from their respective types of data sources, and can be bound to various data-bound controls. Data source controls reduce the number of custom code that you need to write to retrieve and bind data, or even to sort, page, or edit data.

Where the ObjectDataSource control enables declarative data-binding models for a variety of underlying data stores, such as SQL databases or XML. Because page developers also often encapsulate data retrieval (and possibly business logic) in one Component object, introduce another layer between the rendering page and the data provider. The ObjectDataSource control allows developers to construct applications using this traditional three-tier architecture while still leveraging the ease of use of declarative data-binding models in asp.net.

The essential

1. Creating strongly typed datasets and Tableadapter,tableadapter queries at the data layer can use existing stored procedures. Note: Dragging a table or stored procedure directly will create the TableAdapter

2. The classes in the middle tier are declared as data components with [System.ComponentModel.DataObject], and the crud methods correspond to [DataObjectMethod (Dataobjectmethodtype.insert)],[ DataObjectMethod (Dataobjectmethodtype.select)],[dataobjectmethod (dataobjectmethodtype.update)],[ DataObjectMethod (Dataobjectmethodtype.delete)]

3, the Web layer using ObjectDataSource to display data, ObjectDataSource is equivalent to an agent. ObjectDataSource simply finds a method with a matching parameter name that does not use the Type or Size of the parameter, but only matches the name of the parameter

4. Other

The <asp:parameter/> has a ConvertEmptyStringToNull property and the default is true. In addition, there are direction properties

• Pay attention to these attributes of <asp:boundfield/> nulldisplaytext,htmlencode,applyformatineditmode,insertvisible, Dataformatstring,readonly

· DataKeyNames with multiple values separated by the words "," with <asp:controlparameter/> binding to add a "propertyname" attribute, the value is similar to the following "selecteddatakey.values[ 0] "

• About bindings: Simple Properties <%# custid%>; collection <asp:listbox id= "List1" datasource= ' <%# myarray '%> ' runat= ' server ' >; expressions <%# (Customer. FirstName + "" + customer. LastName)%>; method <%# GetBalance (CustID)%>

<%# Eval ("field1")%> and <%# bind ("field1")%>,eval are one-way bound, bind is a two-way state

<asp:objectdatasource/> has a oldvaluesparameterformatstring attribute that is not generally available, but it is used if you want to handle optimistic concurrency. "Original_ parameter name" is the initial value when the value of this property is "original_{0}"

• There are also some such as programming to the parameters of the value, error handling, get the return value and so on to see the source code

Example

Related stored procedures and data layer slightly, see source code

Implementation of single case model

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.