急!如何用adodb实现删除sql server中表的记录!!
记录仍然在表中,没有删除掉,不知道错在哪里,望高手赐教啊。!!!
现有代码
Private cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Private rs As New ADODB.Recordset
Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "当前没有记录要删除!", vbExclamation, "提示"
Else
connectstring = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbname;Data Source=abc"
cnn.Open connectstring
cmd.ActiveConnection = cnn
cmd.CommandText = "select * table1 where id= '" & Trim(Text1.Text) & "'"
rs.Open cmd, , adOpenStatic, adLockBatchOptimistic
If rs.EOF Then
MsgBox "没有符合条件的记录!", vbExclamation, "提示"
Else
reply = MsgBox("真的要删除当前数据吗?", vbOKCancel, "请回答")
If reply = ok Then
cnn.Execute "delete from table1 where id= '" & Trim(Text1.Text) & "'"
End If
End If
rs.Close
cnn.Close
End If
End Sub