急!如何用adodb实现删除sql server中表的记录!!

fengguo1009 2004-08-30 03:47:28
记录仍然在表中,没有删除掉,不知道错在哪里,望高手赐教啊。!!!
现有代码
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

...全文
68 点赞 收藏 2
写回复
2 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
haohaohappy 2004-08-30
改一下:
.................................................................
reply = MsgBox("真的要删除当前数据吗?", vbOKCancel, "请回答")
If reply = 1 Then
cnn.Execute "delete from table1 where id= '" & Trim(Text1.Text) & "'"
.......................................................................
回复
饮水需思源 2004-08-30
connectstring = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=dbname;Data Source=abc"
cnn.Open connectstring
cnn.execute "delete from table1 where [id]='"& trim(text1.text) &"'"
回复
相关推荐
发帖

1188

社区成员

VB 数据库(包含打印,安装,报表)
申请成为版主
帖子事件
创建了帖子
2004-08-30 03:47
社区公告
暂无公告