如何将其他表中的值插入另一个表 [英] how to insert values from other table to another table

查看:90
本文介绍了如何将其他表中的值插入另一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从其他表中插入两个值到表1并从表单控件中插入其他值但是我收到错误我无法理解我的查询错误在哪里





i am inserting two values to a table 1 from other table and other from form control but i am getting error i am not able to understand where is my query wrong


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

推荐答案

当你插入时,列数和类型应匹配并且格式为 INSERT INTO tablename(columns)来自tablename的SELECT(列) http://www.w3schools.com/sql/sql_insert_into_select.asp [ ^ ]

尝试:

When you are inserting then the column count and type should match and the format is INSERT INTO tablename (columns) SELECT (columns) from tablename : http://www.w3schools.com/sql/sql_insert_into_select.asp[^]
try:
INSERT INTO partylinks ( accountid, partyid ) Select max(accountsinfo.accid),2 FROM accountsinfo -- moved the ,2


使用select的INSERT INTO命令的格式如下



The format of INSERT INTO command with select is as follows

INSERT INTO TARGET_TABLE_NAME(Field1, Field2)
SELECT Field1, Field2
FROM   SOURCE_TABLE_NAME





您需要按照上面的说明更改SQL,然后重试



You need to change your SQL as explained above and try again


这篇关于如何将其他表中的值插入另一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆