我用ACCESS数据库
r是日期类型,s是数据类型
删除时,说数据类型不匹配,为什么
Private Sub Command3_Click()
Set rst = New ADODB.Recordset
cnn1.Execute "Delete * From dc1 Where r='" & DataGrid1.Columns(0).Text & "'AND d='" & DataGrid1.Columns(1).Text & "'and k='" & DataGrid1.Columns(2).Text & "'and c='" & DataGrid1.Columns(3).Text & "'and y1='" & DataGrid1.Columns(4).Text & "'AND t='" & DataGrid1.Columns(5).Text & "'and t1='" & DataGrid1.Columns(6).Text & "'and s='" & DataGrid1.Columns(7).Text & "'"
If cnn1.State = adStateOpen Then cnn1.Close
If rst.State = 1 Then rst.Close
cnn1.Open cnnstr
With rst
    .CursorType = adOpenKeyset
    .LockType = adLockOptimistic
    .Open sqlstr, cnn1, , , adCmdText
End With
End Sub

解决方案 »

  1.   

    日期型变量引用:# " & 日期变量 & " #
    数值型变量引用:  " & 数值变量 & "
    SQL语句关键字and的两边要有空格
      

  2.   

    cnn1.Execute "Delete * From dc1 Where r= # " & DataGrid1.Columns(0).Text & " # AND d='" & DataGrid1.Columns(1).Text & "' and k='" & DataGrid1.Columns(2).Text & "'and c='" & DataGrid1.Columns(3).Text & "'and y1='" & DataGrid1.Columns(4).Text & "'AND t='" & DataGrid1.Columns(5).Text & "'and t1='" & DataGrid1.Columns(6).Text & "'and s= " & DataGrid1.Columns(7).Text & " 
    改成这样还是不行,再看看吧