急!如何用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

...全文
107 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
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) &"'"

1,216

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧