Private Sub Command4_Click() '删除本条记录 If Adodc3.Recordset.RecordCount > 1 Then Adodc3.Recordset.Delete'记录表中无记录时,如果要删除,就立即退出 If Adodc3.Recordset.RecordCount > 1 Then Adodc3.Recordset.MoveNext '删除了最后一条记录则退出 End Sub
错了Private Sub Command4_Click() '删除本条记录 If Adodc3.Recordset.RecordCount > 0 Then Adodc3.Recordset.Delete'记录表中无记录时,如果要删除,就立即退出 If Adodc3.Recordset.RecordCount > 0 Then Adodc3.Recordset.MoveNext '删除了最后一条记录则退出 End Sub
用 RecordCount 属性来判断数据量这样不慢才是怪事。 当你调用 RecordCount 属性时,他会遍历一偏,相当于自己数一偏数据量,然后返回给你结果。 数据量少没什么感觉,数据量大就慢很多了,通常在海量数据处理的过程中,RecordCount 属性 是没人去读他的,要知道数据量也是通过 SQL 语句的 Count 聚合函数来查询。 如果能避免使用数据总数,通常可以用 EOF 或 BOF 这类属性来判断数据是否到达边界,这样效率 会高出很多。 If Adodc1.Recordset.EOF Then Exit Sub Adodc3.Recordset.Delete If Adodc1.Recordset.EOF Then Exit Sub Adodc3.Recordset.MoveNext
错误陷井理论上更加快Private Sub Command4_Click() '删除本条记录 On Error Resume Next Adodc3.Recordset.Delete If Err.Number <> 0 Then Err.Clear: Exit Sub Adodc3.Recordset.MoveNext If Err.Number <> 0 Then Err.Clear End Sub
这样好点Private Sub Command4_Click() '删除本条记录 On Error Resume Next If Adodc1.Recordset.EOF Then Exit Sub Adodc3.Recordset.Delete If Err.Number <> 0 Then Err.Clear: Exit Sub Adodc3.Recordset.MoveNext If Err.Number <> 0 Then Err.Clear End Sub
Private Sub Command4_Click() '删除本条记录
If Adodc3.Recordset.RecordCount > 1 Then Adodc3.Recordset.Delete'记录表中无记录时,如果要删除,就立即退出
If Adodc3.Recordset.RecordCount > 1 Then Adodc3.Recordset.MoveNext '删除了最后一条记录则退出
End Sub
If Adodc3.Recordset.RecordCount > 0 Then Adodc3.Recordset.Delete'记录表中无记录时,如果要删除,就立即退出
If Adodc3.Recordset.RecordCount > 0 Then Adodc3.Recordset.MoveNext '删除了最后一条记录则退出
End Sub
当你调用 RecordCount 属性时,他会遍历一偏,相当于自己数一偏数据量,然后返回给你结果。
数据量少没什么感觉,数据量大就慢很多了,通常在海量数据处理的过程中,RecordCount 属性
是没人去读他的,要知道数据量也是通过 SQL 语句的 Count 聚合函数来查询。
如果能避免使用数据总数,通常可以用 EOF 或 BOF 这类属性来判断数据是否到达边界,这样效率
会高出很多。 If Adodc1.Recordset.EOF Then Exit Sub
Adodc3.Recordset.Delete
If Adodc1.Recordset.EOF Then Exit Sub
Adodc3.Recordset.MoveNext
On Error Resume Next
Adodc3.Recordset.Delete
If Err.Number <> 0 Then Err.Clear: Exit Sub
Adodc3.Recordset.MoveNext
If Err.Number <> 0 Then Err.Clear
End Sub
On Error Resume Next
If Adodc1.Recordset.EOF Then Exit Sub
Adodc3.Recordset.Delete
If Err.Number <> 0 Then Err.Clear: Exit Sub
Adodc3.Recordset.MoveNext
If Err.Number <> 0 Then Err.Clear
End Sub