如何从另一个表中插入值

时间:2021-06-01 09:24:59

I am inserting two values to a table, one from another table and the other from form control but I am getting an error.

我正在向表中插入两个值,一个来自另一个表,另一个来自表单控件但我收到错误。

 sqlstr = "INSERT INTO partylinks ( accountid, partyid ) values(Select max(accountsinfo.accid) FROM accountsinfo,2 )"
                cmd = New OleDb.OleDbCommand(sqlstr, con, tra)
                cmd.ExecuteNonQuery()

1 个解决方案

#1


You don't use the VALUES syntax if you are SELECTing

如果要选择,则不使用VALUES语法

Try:

sqlstr = "INSERT INTO partylinks (accountid, partyid) Select max(accountsinfo.accid),2 AS partyid FROM accountsinfo"

#1


You don't use the VALUES syntax if you are SELECTing

如果要选择,则不使用VALUES语法

Try:

sqlstr = "INSERT INTO partylinks (accountid, partyid) Select max(accountsinfo.accid),2 AS partyid FROM accountsinfo"