mysql - 如何使用vba连接mysql数据库?
问题描述
选项显式
Sub excelmysql() ' 连接变量 Dim conn As New ADODB.Connection Dim Server_Name As String Dim Database_Name As String Dim User_ID As String Dim Password As String ' 表动作变量 Dim i As Long ' counter Dim strSQL As String ' 执行各种动作的 SQL将表 1 调暗为字符串 将字段 1 调为字符串,将字段 2 调为字符串 调暗 rs 为 ADODB.Recordset 调暗 vtype 作为变体
Server_Name = "localhost" ' 在此处输入您的服务器名称 - 如果从本地计算机运行,请使用 127.0.0.1
Database_Name = "PRMJIRA" ' 在此处输入您的数据库名称
User_ID = "root" ' 在此处输入您的用户 ID
Password = "Pradee@1234" ' 在此输入您的密码
Set conn = New ADODB.Connection
conn.Open "DRIVER={MySQL ODBC 8.0 Unicode Driver}" _
& ";SERVER=" & Server_Name _
& ";DATABASE=" & Database_Name _
& ";UID=" & User_ID _
& ";PWD=" & Password _
& ";OPTION=16427"
'conn.Open
vtype = Array("varchar(255)", "Text", "LongText", "Int(10)", "Float", "Double", "Date", "Time") ' array of commonly used MySQL variable types
table1 = "P" & Range("H1").Value
field1 = "field1text"
field2 = "field2text"
strSQL = "CREATE TABLE `" & table1 & "` (`" _
& field1 & "` " & vtype(0) & ",`" _
& field2 & "` " & vtype(4) _
& ")"
conn.Execute strSQL
On Error Resume Next
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
On Error GoTo 0
结束子
解决方案
推荐阅读
- java - Java Eclipse中的Serializer()方法“未定义构造函数序列化器()”
- php - Eloquent:复合 WhereIn 条件
- c++ - 如何安排操作在未来时间运行
- c++ - 有没有办法使用 glDrawPixels 渲染单通道灰度图像?
- android-studio - Android Studio 3.5 中的 Gradle `project` 变量
- c - 在 C 中的循环中读取字符串时从 sscanf 获取偏移量
- eclipse - 从 Eclipse 工作区中删除文件夹
- elasticsearch - 对 SQL 的弹性查询
- java - 为什么我得到@WebServlet 注释但没有实现javax.servlet.http.HttpServlet 接口。使用 vaadinCDI Servlet 时出现错误
- php - 通过 Woocommerce 管理订单中的自定义操作按钮使用订单项目元数据