我正在寻找一组代码,允许我一次将8行数据插入到SQL数据库表的表中。
这样的事,
sqlur = objCon.CreateCommand()
strSQL = "INSERT INTO RESULTS (CandidateNumber,CandidateName,VotesReceived) VALUES ('" & candNo1 & "', '" & votefname1 & "','" & votesgot1 & "');"
'strSQL = "INSERT INTO RESULTS (CandidateNumber,CandidateName,VotesReceived) VALUES ('" & candNo2 & "', '" & votefname2 & "','" & votesgot2 & "');"
谢谢你!
答案 0 :(得分:1)
通常我会避免使用Values函数,如果值来自另一个表,则使用SELECT语句。
INSERT INTO RESULTS (CandidateNumber, CandidateName, VotesReceived)
SELECT candNo, votefname, votesgot
FROM ResultsTable
答案 1 :(得分:0)
您可以使用这样的SQL:
INSERT INTO RESULTS (CandidateNumber, CandidateName, VotesReceived) VALUES (
1, 'NAME 1', 100,
2, 'NAME 2', 150,
3, 'NAME 1', 57,
4, 'NAME 4', 100,
5, 'NAME 5', 28,
6, 'NAME 6', 57,
7, 'NAME 7', 38,
8, 'NAME 8', 294
)