Excel の VBA モジュール。ADODB.Connection とこの接続文字列を使用します。
"Provider=SQLOLEDB;Data Source=MARS;Initial Catalog=automation;Trusted_connection=yes;"
したい:
- INSERT INTO テスト (データ) VALUES ('何か')
- 新しく挿入された行の自動増分 ID (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)