Mega Code Archive

 
Categories / ASP.Net / ADO Database
 

Detecting concurrency errors after updating data (C#)

<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void SqlDataSource1_Updated(object sender, SqlDataSourceStatusEventArgs e) {     if (e.AffectedRows > 0)         Message.Text = "The record has been updated";     else         Message.Text = "Possible concurrency violation"; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title>Untitled Page</title> </head> <body>     <form id="form1" runat="server">     <div>         <asp:SqlDataSource ID="SqlDataSource1"                             Runat="server"                             SelectCommand="SELECT * FROM [Customers] WHERE ([CustomerID] = @CustomerID)"                            ConnectionString="<%$ ConnectionStrings:AppConnectionString1 %>"                            DataSourceMode="DataSet"                            ConflictDetection="CompareAllValues"                             OnUpdated="SqlDataSource1_Updated">             <SelectParameters>                 <asp:QueryStringParameter Name="CustomerID"                                            QueryStringField="id"                                            Type="String">                 </asp:QueryStringParameter>             </SelectParameters>         </asp:SqlDataSource>         <asp:Label ID="Message" runat="server" Text="Label"></asp:Label>     </div>     </form> </body> </html>