use*_*094 3 sql-server excel vba ado
在 Excel 的 VBA 模块中。使用 ADODB.Connection 和此连接字符串:
"Provider=SQLOLEDB;Data Source=MARS;Initial Catalog=automation;Trusted_connection=yes;"
Run Code Online (Sandbox Code Playgroud)
我想要:
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)
Run Code Online (Sandbox Code Playgroud)