VB批量更新数据库中的记录
PrivateSubCommand1_Click()IfAdodc1.Recordset.RecordCount>0ThenAdodc1.Recordset.MoveFi...
Private Sub Command1_Click()
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Adodc1.Recordset.MoveNext
Loop
End If
End Sub
上面的代码我试过,没错,但删一条更新一次,我总觉得太笨,我想改成下面的
Private Sub Command1_Click()
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
Loop
End If
Adodc1.Recordset.Update
End Sub
结果却报错,是什么原因呢,能说下吗?我的意思是想批量删除,一次更新,如果不用UpdateBatch,怎样改?如果用UpdateBatch呢?
务求详细! 展开
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Adodc1.Recordset.MoveNext
Loop
End If
End Sub
上面的代码我试过,没错,但删一条更新一次,我总觉得太笨,我想改成下面的
Private Sub Command1_Click()
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
Loop
End If
Adodc1.Recordset.Update
End Sub
结果却报错,是什么原因呢,能说下吗?我的意思是想批量删除,一次更新,如果不用UpdateBatch,怎样改?如果用UpdateBatch呢?
务求详细! 展开
展开全部
试试这个代码:
Private Sub Command1_Click()
If Adodc1.Recordset.RecordCount > 0 Then
for i=0 to Adodc1.Recordset.RecordCount-1
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Delete
Adodc1.Recordset.Move i
next
Adodc1.Recordset.Update
End If
End Sub
Private Sub Command1_Click()
If Adodc1.Recordset.RecordCount > 0 Then
for i=0 to Adodc1.Recordset.RecordCount-1
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Delete
Adodc1.Recordset.Move i
next
Adodc1.Recordset.Update
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询