插入了一条记录,提示有重复 但还是插进了数据库,是怎么回事啊
If rs.RecordCount > 0 Then
               MsgBox "登陆名已经存在!", vbOKOnly + vbExclamation, "警告!"
               TxtLoginName.SetFocus
              
            rs.Close
            DataGridLogin.Refresh
        Else
           Adodc1.Recordset.Update
           Adodc1.Refresh

解决方案 »

  1.   

    前面的代码呢?光这一句看不出什么。或者在 msgbox 前加一句:objRs.CancelUpdate
      

  2.   

    Set cn = New ADODB.Connection 
        cn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=True;User ..............."
        cn.CursorLocation = adUseClient
        cn.Open
        Dim str As String
        str = "select * from login where loginName='" & Trim(TxtLoginName) & "'"
        rs.Open str, cn
            If rs.RecordCount > 0 Then
                   MsgBox "登陆名已经存在!", vbOKOnly + vbExclamation, "警告!"
                   TxtLoginName.SetFocus
                rs.Close
                
            Else
               Adodc1.Recordset.Update
               Adodc1.Refresh
               DataGridLogin.Refresh
      

  3.   

    用的是 adodc 控件?更新是自动完成的?没看到更新代码嘛!麻烦...
    偶从不用数据库件,都是 adodb.recordset 对象,操作起来灵活一些。
      

  4.   

    试试:If rs.RecordCount > 0 Then
                   MsgBox "登陆名已经存在!", vbOKOnly + vbExclamation, "警告!"
                   TxtLoginName.SetFocus
                rs.Closeadodc1.Recordset.CancelUpdateelse
    ....