用全匹配方式解决并发多人修改同一个表的问题

本文探讨如何使用全匹配策略来有效防止并发环境下多人同时修改同一数据库表导致的数据冲突问题,确保数据一致性。
摘要由CSDN通过智能技术生成

Partial Class User
    Inherits System.Web.UI.Page

    Private Sub BindData()
        Using sds As SqlDataSource = New SqlDataSource("Data Source=.;Initial Catalog=master;User ID=sa;Password=Abcdefg1", "select * from t_user order by usernumb desc")
            Me.GridView1.DataSource = sds
            Me.GridView1.DataBind()
        End Using
    End Sub

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        Me.GridView1.PageIndex = e.NewPageIndex
        Me.GridView1.EditIndex = -1
        Me.BindData()
    End Sub

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Request.Cookies("username") IsNot Nothing And Request.Cookies("userpass") IsNot Nothing Then
            Dim username As String = HttpUtility.UrlDecode(Request.Cookies("username").Value)
            Dim userpass As String = HttpUtility.UrlDecode(Request.Cookies("userpass").Value)
            Using sds As SqlDataSource = New SqlDataSource("Data Source=.;Initial Catalog=master;User ID=sa;Password=Abcdefg1", "select count(*) from t_user where username = @username and userpass = @userpass and a = 1")
                sds.SelectParameters.Add("username", username)
                sds.SelectParameters.Add("userpass", userpass)
                Dim i As Integer = DirectCast(sds.Select(DataSourceSelectArguments.Empty), System.Data.DataView)(0)(0)
                If i = 0 Then
                    Response.Redirect("~/Index.aspx")
                End If
            End Using
        Else
            Response.Redirect("~/Default.aspx")
        End If
        If Not IsPostBack Then
            Me.BindData()
        End If
    End Sub

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        Me.GridView1.EditIndex = -1
        Me.BindData()
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        Dim s As String = e.CommandName
        If s.Equals("insert") Then
            Dim username As String = DirectCast(Me.GridView1.FooterRow.FindControl("txt_username"), TextBox).Text
            Dim userpass As String = DirectCast(Me.GridView1.FooterRow.FindControl("txt_userpass"), TextBox).Text
            Dim ba As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_a"), CheckBox).Checked
            Dim bb As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_b"), CheckBox).Checked
            Dim bc As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_c"), CheckBox).Checked
            Dim bd As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_d"), CheckBox).Checked
            Dim be As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_e"), CheckBox).Checked
            Dim bf As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_f"), CheckBox).Checked
            Dim bg As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_g"), CheckBox).Checked
            Dim bh As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_h"), CheckBox).Checked
            Dim bi As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_i"), CheckBox).Checked
            Dim bj As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_j"), CheckBox).Checked
            Dim bk As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_k"), CheckBox).Checked
            Dim bl As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_l"), CheckBox).Checked
            Dim bm As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_m"), CheckBox).Checked
            Dim bn As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_n"), CheckBox).Checked
            Dim bo As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_o"), CheckBox).Checked
            Dim bp As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_p"), CheckBox).Checked
            Dim bq As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_q"), CheckBox).Checked
            Dim br As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_r"), CheckBox).Checked
            Dim bs As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_s"), CheckBox).Checked
            Dim bt As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_t"), CheckBox).Checked
            Dim bu As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_u"), CheckBox).Checked
            Dim bv As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_v"), CheckBox).Checked
            Dim bw As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_w"), CheckBox).Checked
            Dim bx As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_x"), CheckBox).Checked
            Dim by As Boolean = DirectCast(Me.GridView1.FooterRow.FindControl("cb_y"), CheckBox).Checked
            Dim bz As Boolean = Dire
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值