我有查询,我想通过vba将其插入数据库

时间:2016-10-14 06:59:02

标签: database excel-vba vba excel

但它将字符串插入到图像中的数据库中。当我删除“”然后显示错误无效的列名称。

query = "select code from info"
conn.Execute "insert into dbo.Customers (AccountNo,Amount,code) values ('" & AccountNo & "', '" & Amount & "', query)"

enter image description here

1 个答案:

答案 0 :(得分:0)

如果使用mssql

,可以试试这个
query = "select top 1 code from info"
conn.Execute "insert into dbo.Customers (AccountNo,Amount,code) " & _
             "values ('" & AccountNo & "', '" & Amount & "', ("& query &"))"

它将在查询

中执行子查询
相关问题