连接到MySQL并执行数据库查询(通过VBA)后,当我尝试向结果集的元素分配变量时,Excel崩溃。
一开始它运行良好,但随后突然停止工作。 Excel2016。MySql 5.1.35社区服务器(GPL)
Sub doSomething()
call conectBD
Dim cSQL as String
Dim rstSet as RecordSet
Dim myName as String
cSQL = "SELECT name FROM tbNames WHERE id_name=3"
Set rstSet = New ADOBD.Recordset
rstSet.Open cSQL, conexao, adOpenStatic, adLockReadOnly
myName = rstSet!name 'Excel crashes here'
rstSet.Close
Set rstSet = Nothing
call disconectBD
end Sub
'Connect to BD'
sub conectBD()
Set conexao = New ADODB.Connection'Connection'
conexao.ConnectionString = "DRIVER={MySQL ODBC 5.1 Driver};" _
& "SERVER=localhost;" _
& "DATABASE=DB;" _
& "UID=user;" _
& "PASSWORD=password"
conexao.Open
End sub
'Disconnet to BD'
sub disconectBD()
conexao.close
set conexao = nothing
end sub
我希望它像开始时一样工作。