Private Sub 删除_Click() Dim mycom As New ADODB.Command
 Dim count As Long
 Dim constr, sql As String
 Set con = New ADODB.Connection
 Set rst = New ADODB.Recordset
 Set mycom = New ADODB.Command  constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=I:\毕设5.20\db1.mdb; Persist Security Info=False "
  con.Open constr
  If con.State = adStateOpen Then
   MsgBox "打开数据库"
  End If
  Set mycom.ActiveConnection = con
 '调用查询函数查询出要删除的记录
  Call 查询_Click   sql = "delete from author where " & strWhere & ""
   MsgBox (sql)
   mycom.CommandText = sql
   MsgBox ("删除成功")
   rst.Open mycom, , adOpenStatic, adLockOptimistic Set con = Nothing
End Sub
可以查询出要删除的记录,并在子窗体中显示,但rs.RecordCount却为0,通过delete对数据表进行操作也无效!各位大哥大姐帮帮忙,很着急。

解决方案 »

  1.   

    strWhere的值是什么?调试下。
      

  2.   

    strWhere是从页面获取的查询条件,没问题,可以通过这个条件查询出数据表中的记录,但对该信息进行删除却无效。
      

  3.   

    tryPrivate Sub 删除_Click()
        
        Dim mycom As New ADODB.Command
        Dim count As Long
        Dim constr, sql As String
        
        Set con = New ADODB.Connection
        Set rst = New ADODB.Recordset
        Set mycom = New ADODB.Command
        
        constr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=I:\毕设5.20\db1.mdb; Persist Security Info=False "
        con.Open constr
        
        If con.State = adStateOpen Then
            MsgBox "打开数据库"
        End If
        
        Set mycom.ActiveConnection = con
        '调用查询函数查询出要删除的记录
        Call 查询_Click
        
        sql = "delete from author where " & strWhere & ""
        MsgBox (sql)
        con.Execute sql
        MsgBox ("删除成功")
        
        Set con = Nothing
    End Sub
      

  4.   

    Dim AffectedRecords As Long
        sql = "delete from author where " & strWhere & ""
        MsgBox (sql)
        con.Execute sql, AffectedRecords
        MsgBox ("删除" & AffectedRecords & "条记录")
      

  5.   


    在 Execute 方法中,如果没有符合 Where 子句条件的记录,并不会返回错误,只是没有删除或更新任何记录而已。
      

  6.   

    数据库里面有符合条件的信息,查询可以显示在子窗体中,rs.RecordCount却为空,执行delete语句也对数据信息改变不了,很郁闷