3

在 Excel 的 VBA 模块中。使用 ADODB.Connection 和此连接字符串:

"Provider=SQLOLEDB;Data Source=MARS;Initial Catalog=automation;Trusted_connection=yes;"

我想要:

  1. 插入测试(数据)值(“某事”)
  2. 检索新插入行的自动递增标识 (test.data_id)。
4

1 回答 1

5
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)
于 2013-02-10T23:39:08.467 回答