CSharp Detecting Concurrency Errors After Updating Data (C#) – ADO.Net Database

<%@ 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>

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.