ASP. net2.0 revealing Reading Notes 4: concurrency issues in updating data processing using the gridview Control

Source: Internet
Author: User

GridviewYou can save the original value and the new value of each data column at the same time, so you can handle concurrency conflicts.

<%@ Page Language= "C #" %>

<!Doctype Html Public "-// W3C // dtd xhtml 1.1 // en" Http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd>

<Html Xmlns= "Http://www.w3.org/1999/xhtml" >

<Head ID= "Head1" Runat= "Server">

<Title>Concurrency</Title>

</Head>

<Body>

<Form ID= "Form1" Runat= "Server">

<Div>

<ASP:Gridview

ID= "Grdmovies"

Performanceid= "Srcmovies"

Datakeynames= "ID"

Autogenerateeditbutton= "True"

Runat= "Server" />

<ASP:Sqldatasource

ID= "Srcmovies"

Conflictdetection= "Compareallvalues"

Oldvaluesparameterformatstring= "Original _ {0 }"

Connectionstring="<%$ Connectionstrings: Movies%>"

Selectcommand= "Select ID, title, Director from movies"

Updatecommand= "Update movies set Title = @ title, Director = @ Director

Where id = @ original_id and Title = @ original_title and Director = @ original_director"

Runat= "Server" />

</Div>

</Form>

</Body>

</Html>

 

AboveCodeIn the list,SqldatasourceControlConflicatdetectionAttributes andOldvaluesparameterformatstringAttribute values are assigned.SqldatasourceControl to keep the original value and modified value of this column for each data column.

ConflicatdetectionThe attribute can be one of the following two values:

Compareallvalues

Overwritechanges

ConflicatdetectionThe default value isOverwritechanges, This will causeSqldatasourceThe control directly overwrites the data column with the new value. IfCompareallvalues,SqldatasourceThe control retains the original value and modified value for each column.

OldvaluesparameterformatstringAttribute is used to provide a unique name for the column's original value. For example,SqldatasourceControlUpdatecommandThe attribute values are as follows:

Updatecommand= "Update movies set Title = @ title, Director = @ Director

Where id = @ original_id and Title = @ original_title and Director = @ original_director"

 

@ Original_id, @ Original_title, @ original_director parameter indicates the original values of these columns. If you modify these records first, this modification is ignored.

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.