Private Sub Command1_Click(Index As Integer) If Adodc1.Recordset.RecordCount > 0 Then Adodc1.Recordset.MoveFirst For i = 1 To Adodc1.Recordset.RecordCount If Not Adodc1.Recordset.EOF Then Adodc1.Recordset.Delete doevents Adodc1.Recordset.MoveNext End If Next i Else Exit Sub End If End Sub
我用想改用ADO对象。
但是我不知道ADO对象的增加一条记录、删除一条记录、以及怎样连接DataGird控件
If Adodc1.Recordset.RecordCount > 0 Then
For i = 1 To Adodc1.Recordset.RecordCount
If Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Delete
End If
Next i
Else
Exit Sub
End If
End Sub学习.关注.
dim a as integer
a=adodc1.recordset.recordcount
If a> 0 Then
Adodc1.Recordset.MoveFirst
For i = 1 To a-1
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
Next i
Adodc1.Recordset.Delete
Else
Exit Sub
End If
End Sub错误原因:在DELETE最后一条记录后,有一句Adodc1.Recordset.MoveNext
在空记录集里用MOVENEXT会出错还有,可以省去判断,以加快速度
2.建立其与您数据库的联接:Connection1
3.建立一个命令:Cmdxxx
执行代码:
'---------------------------
DataEvionment1.rsCmdxxx.Open
SQL = "delete * from 表名"
DataEvionment1.Connection1.Execute SQL
DataEvionment1.rsCmdxxx.Update
DataEvionment1.rsCmdxxx.Close
'----------------------------
可一次性删除所有记录注:用数据环境操作ADO有很多优点,您可参考一下有关资料。
怎么用它连接DataGird控件?
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
For i = 1 To Adodc1.Recordset.RecordCount
If Not Adodc1.Recordset.EOF Then
Adodc1.Recordset.Delete
doevents
Adodc1.Recordset.MoveNext
End If
Next i
Else
Exit Sub
End If
End Sub