【VB】VB 連接MYQSL
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
下面給你的代碼是百分之百可以連接成功的,它也是我正在使用中的代碼片段哦。 Private Sub Command1_Click() Dimcn As New ADODB.Connection '創(chuàng)建數(shù)據(jù)庫對象 Dimrs As New ADODB.Recordset '創(chuàng)建表對象 DimstrCn As String '連接字符串 Dimdb_host As String Dimdb_user As String Dimdb_pass As String Dimdb_data As String db_host = "188.88.88.188" '服務(wù)器IP地址 db_user = "users" '登陸服務(wù)器時(shí)的“用戶名” db_pass = "passwords" '登陸服務(wù)器時(shí)的“密 碼” db_data = "sqlname" '數(shù)據(jù)庫的庫名稱sqlname(不是表名稱) strCn = "DRIVER={MySQL ODBC 3.51 Driver};" &"SERVER=" & db_host & ";" &"DATABASE=" & db_data & ";" & _ "UID=" & db_user & ";PWD=" & db_pass& ";" & "OPTION=3;stmt=SET NAMES GB2312" cn.Open strCn '打開數(shù)據(jù)庫 cn.CursorLocation = adUseClient Ifcn.State = adStateOpen Then MsgBox "打開遠(yuǎn)程MySQL數(shù)據(jù)庫成功" '下面開始對具體表(假設(shè)"userstabel")進(jìn)行操作 rs.Open "userstabel", cn, adOpenKeyset, adLockOptimistic '打開表"userstabel" MsgBox "遠(yuǎn)程數(shù)據(jù)表userstabel 中的記錄數(shù)量= " & rs.RecordCount rs.AddNew '開始添加一條記錄 rs.Fields("filed1") = x rs.Fields("filed2") =y rs.Fields("filed2") = z rs.Update rs.Close '關(guān)閉表 cn.Close '關(guān)閉數(shù)據(jù)庫 Ifcn.State = adStateClosed Then MsgBox "遠(yuǎn)程數(shù)據(jù)庫MySQL關(guān)閉成功" End Sub 首先將myodbc3.dll文件復(fù)制到系統(tǒng)下,然后將以下內(nèi)容做成xxx.reg文件并運(yùn)行。 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\MySQL AB\MySQLConnector/ODBC 3.51] "Version"="3.51.24" [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\MySQLODBC 3.51 Driver] "UsageCount"=dword:00000001 "Driver"="C:\\WINDOWS\\system32\\myodbc3.dll" "Setup"="C:\\WINDOWS\\system32\\myodbc3S.dll" [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBCDrivers] "MySQL ODBC 3.51Driver"="Installed" 該文章在 2013/11/13 23:40:49 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |