以下代码错误就MsgBox cn.RecordsAffected
行了:
参数类型错误、超出可接受范围或相互冲突。
如何成功获取受影响的行数?这是针对 Access 2003 项目的。我更愿意将其保留为 2003 格式,所以如果有其他方法可以做到这一点,那就太好了。为了这个 1 功能,我不想升级整个项目。
Private Sub Command21_Click()
On Error GoTo Err1:
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection
With cn
.Provider = "SQL Native Client"
.ConnectionString = "Server=myserver\myinstance;Database=mydb;Uid=myuser;Pwd=mypass;]"
.Open
End With
On Error GoTo Err2:
cn.Execute "SELECT * INTO someschema.sometable FROM someschema.anothertable"
MsgBox cn.RecordsAffected
Exit Sub
Err1:
MsgBox "Failed to connect to database!"
Exit Sub
Err2:
MsgBox Err.DESCRIPTION
cn.Close
End Sub