在 Excel 的 VBA 模块中。使用 ADODB.Connection 和此连接字符串:
"Provider=SQLOLEDB;Data Source=MARS;Initial Catalog=automation;Trusted_connection=yes;"
我想要:
- 插入测试(数据)值(“某事”)
- 检索新插入行的自动递增标识 (test.data_id)。
在 Excel 的 VBA 模块中。使用 ADODB.Connection 和此连接字符串:
"Provider=SQLOLEDB;Data Source=MARS;Initial Catalog=automation;Trusted_connection=yes;"
我想要:
Dim identity as integer
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.ConnectionString = "whatever..."
cn.Open
cn.Execute ("INSERT INTO test(data) VALUES ('hello world')")
rs.Open "SELECT @@identity AS NewID", cn
identity = rs.Fields("NewID")
MsgBox (identity)