--------------------------------------连接部分------------------------------------------------------
Dim Cnn
Set Cnn = CreateObject("ADODB.Connection")
Cnn.ConnectionString ="DATABASE=testmysql;DSN=192.168.1.63;OPTION=0WD=123456ORT=0;SERVER=192.168.1.63;UID=root"
Cnn.Open
If Cnn.State = 0 Then
Reporter.ReportEvent micFail, "testing", "连接数据库失败"
else
Reporter.ReportEvent micPass, "testing", "连接数据库成功"
end if
--------------------------------------操作部分------------------------------------------------------
Set Rs = CreateObject("ADODB.Recordset")
Rs.Open"select DC_CODE from MENUS_DEPARTMENT_CLASS",Conn '后面可以加上参数表示打开的方式
Rs.movefirst
While not rs.eof
MsgBox(Rs("DC_CODE").value)
Rs.movenext
wend
Rs.Close
Conn.Close
Set Rs = nothing
Set Conn = nothing
记录集对象的方法: