简体   繁体   English

在 Visual Basic 中使用 Windows 窗体在一个命令中使用多个 SQL 插入语句将多行插入到表中,

[英]Using multiple SQL insert statements in one command to insert multiple rows to a table using a windows form in Visual Basic,

i am seeking for a set of code which would allow me to insert 8 rows of data at once in to a table in a SQL database table.我正在寻找一组代码,它允许我一次将 8 行数据插入到 SQL 数据库表中的表中。

something like this,像这样的东西,

        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 & "');"

thank you !谢谢你 !

Typically I avoid using the Values function and go with a SELECT statement if the values come from another table.通常,如果值来自另一个表,我会避免使用 Values 函数并使用 SELECT 语句。

INSERT INTO RESULTS (CandidateNumber, CandidateName, VotesReceived)
SELECT candNo, votefname, votesgot
FROM ResultsTable

You can use a SQL like this:您可以使用这样的 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
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM