我试图找出此错误消息:
在SQL语句结束时缺少分号。
我现在使用MS Access作为数据库,我有2个表:users和import_users_temp_excel。我想将数据从MS Excel导入到import_users_temp_excel,然后将新的注册表合并或复制到表" users"中。基本上,我想避免重复使用"用户"表。这是我的代码:
Dim sqlquery1 As New OleDbCommand
sqlquery1.Connection = con
sqlquery1.CommandType = CommandType.Text
sqlquery1.CommandText = "insert into users ([employeeID], [username], [middlename], [lastname], [level], [ADDR1], [ADDR2], [city], [state], [zip], [warehouse_assig], [timezone], [branchM], [contactinfo], [email], [altemail], [Source]) values(@employeeID, @username, @middlename, @lastname, @level, @ADDR1, @ADDR2, @city, @state, @zip, @warehouse_assig, @timezone, @branchM, @contactinfo, @email, @altemail, @Source)
select distinct * from import_users_temp_excel;"
但由于某种原因,我得到了这个错误"缺少分号"。我正在使用Visual Studio Community 2015。
答案 0 :(得分:0)
正如评论所提到的,您的INSERT
和SELECT
是两个不同的陈述,因此它们都需要分号才能终止它们。
试试这个 -
sqlquery1.CommandText = "insert into users ([employeeID], [username], [middlename], [lastname], [level], [ADDR1], [ADDR2], [city], [state], [zip], [warehouse_assig], [timezone], [branchM], [contactinfo], [email], [altemail], [Source])
values (@employeeID, @username, @middlename, @lastname, @level, @ADDR1, @ADDR2, @city, @state, @zip, @warehouse_assig, @timezone, @branchM, @contactinfo, @email, @altemail, @Source);
select distinct * from import_users_temp_excel;"
答案 1 :(得分:0)
Dim strsql As String = "insert into users SELECT * FROM import_users_temp_excel WHERE import_users_temp_excel.employeeID Not IN (SELECT employeeID from users)"
Dim command1 As New OleDbCommand
command1 = New OleDbCommand(strsql, con)
command1.ExecuteNonQuery()
con.Close()
loaddata()