语法错误 INSERT INTO 语句 - ACCESS DB

Syntax error INSERT INTO statement - ACCESS DB

从昨天开始,我已经取得了长足的进步!大声笑我现在正在通过添加记录来测试我的数据库项目。我有 58 个字段,所以 INSERT INTO 语句很长。无论我尝试什么(据我所知,google 必须提供的一切),我都会在运行时遇到语法错误,即语法错误 INSERT INTO 语句。这是我使用的代码:

Private Sub AddRecord()
    'Add Parameters
    Access.AddParam("@v1", txtPrograms.Text)
    Access.AddParam("@v2", dtpQADate.Value.ToShortDateString)
    Access.AddParam("@v3", txtReviewer.Text)
    Access.AddParam("@v4", cmbAssessment.SelectedItem.ToString)
    Access.AddParam("@v5", dtpAssessment.Value.ToShortDateString)
    Access.AddParam("@v6", cmbScreening.SelectedItem.ToString)
    Access.AddParam("@v7", dtpScreening.Value.ToShortDateString)
    Access.AddParam("@v8", cmbStatusIndicators.SelectedItem.ToString)
    Access.AddParam("@v9", dtpStatusIndicators.Value.ToShortDateString)
    Access.AddParam("@v10", cmbHealthRecord.SelectedItem.ToString)
    Access.AddParam("@v11", dtpHealthRecord.Value.ToShortDateString)
    Access.AddParam("@v12", cmbSA.SelectedItem.ToString)
    Access.AddParam("@v13", dtpSA.Value.ToShortDateString)
    Access.AddParam("@v14", cmbFrail.SelectedItem.ToString)
    Access.AddParam("@v15", txtFrailExplain.Text)
    Access.AddParam("@v16", cmbDrAppt.SelectedItem.ToString)
    Access.AddParam("@v17", txtDrApptExplain.Text)
    Access.AddParam("@v18", cmbApptTracking.SelectedItem.ToString)
    Access.AddParam("@v19", cmbCurrent.SelectedItem.ToString)
    Access.AddParam("@v20", txtEFGuidelines.Text)
    Access.AddParam("@v21", cmbOrdersInPlace.SelectedItem.ToString)
    Access.AddParam("@v22", cmbOrdersCorrect.SelectedItem.ToString)
    Access.AddParam("@v23", txtAllergies.Text)
    Access.AddParam("@v24", cmbCertEntries.SelectedItem.ToString)
    Access.AddParam("@v25", cmbCertEntriesNo.SelectedItem.ToString)
    Access.AddParam("@v26", txtPC1.Text)
    Access.AddParam("@v27", dtpPC1.Value.ToShortDateString)
    Access.AddParam("@v28", txtPC2.Text)
    Access.AddParam("@v29", dtpPC2.Value.ToShortDateString)
    Access.AddParam("@v30", txtPC3.Text)
    Access.AddParam("@v31", dtpPC3.Value.ToShortDateString)
    Access.AddParam("@v32", txtPC4.Text)
    Access.AddParam("@v33", dtpPC4.Value.ToShortDateString)
    Access.AddParam("@v34", txtPC5.Text)
    Access.AddParam("@v35", dtpPC5.Value.ToShortDateString)
    Access.AddParam("@v36", txtPC6.Text)
    Access.AddParam("@v37", dtpPC6.Value.ToShortDateString)
    Access.AddParam("@v38", txtPC7.Text)
    Access.AddParam("@v39", dtpPC7.Value.ToShortDateString)
    Access.AddParam("@v40", txtPC8.Text)
    Access.AddParam("@v41", dtpPC8.Value.ToShortDateString)
    Access.AddParam("@v42", cmbLogComplete.SelectedItem.ToString)
    Access.AddParam("@v43", cmbLogCorrect.SelectedItem.ToString)
    Access.AddParam("@v44", cmbPRNComplete.SelectedItem.ToString)
    Access.AddParam("@v45", cmbPRNCorrect.SelectedItem.ToString)
    Access.AddParam("@v46", cmbNoProtocols.SelectedItem.ToString)
    Access.AddParam("@v47", txtControlled.Text)
    Access.AddParam("@v48", txtWasted.Text)
    Access.AddParam("@v49", cmbAccurate.SelectedItem.ToString)
    Access.AddParam("@v50", cmbCapable.SelectedItem.ToString)
    Access.AddParam("@v51", dtpSelfAdmin.Value.ToShortDateString)
    Access.AddParam("@v52", cmbLocked.SelectedItem.ToString)
    Access.AddParam("@v53", cmbOTC.SelectedItem.ToString)
    Access.AddParam("@v54", cmbOTCNo.SelectedItem.ToString)
    Access.AddParam("@v55", dtpPermit.Value.ToShortDateString)
    Access.AddParam("@v56", dtpWaiver.Value.ToShortDateString)
    Access.AddParam("@v57", cmbErrors.SelectedItem.ToString)
    Access.AddParam("@v58", txtNotesFinal.Text)

    'Execute Insert Command
    Access.ExecQuery("INSERT INTO tblQA ([Program],[assessdate],[Reviewer],[healthassess],[healthassessdate],[Screening],[screeningdate],[healthindicators],[healthindicatorsdate],[healthrecord],[healthrecorddate],[sareview],[sareviewdate],[Frail],[frailexplanation],[drappt],[drapptexplanation],[trackingform],[trackingformcorrect],[efguidelines],[ordersinplace],[orderscorrect],[Allergies],[certentries],[certentriesnum],[pc1],[pc1date],[pc2],[pc2date],[pc3],[pc3date],[pc4],[pc4date],[pc5],[pc5date],[pc6],[pc6date],[pc7],[pc7date],[pc8],[pc8date],[logdoccomplete],[logdoccorrect],[prnprotocolscomplete],[prnprotocolscorrect],[numprnprotocols],[cmedslist],[cmedslistwasted],[cmedslistaccurate],[selfadmincapable],[selfadminevaldate],[medslocked],[otcforms],[otcnum],[permitadmindate],[epwaiverdate],[numerrors],[Notes] ) _
                    VALUES (@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13,@v14,@v15,@v16,@v17,@v18,@v19,@v20,@v21,@v22,@v23,@v24, @v25,@v26,@v27,@v28,@v29,@v30,@v31,@v32,@v33,@v34,@v35,@v36,@v37,@v38,@v39,@v40,@v41,@v42,@v43,@v44,@v45,@v46,@v47,@v48,@v49,@v50,@v51,@v52,@v53,@v54,@v55,@v56,@v57,@v58);")

我检查过类似的帖子,但 none 似乎解决了我的问题。 感谢您再次花时间指导我!

您错误地将 VB 行继续符放在 String.

如果你想使用续行符,这个:

Access.ExecQuery("INSERT INTO tblQA ([Program],[assessdate],[Reviewer],[healthassess],[healthassessdate],[Screening],[screeningdate],[healthindicators],[healthindicatorsdate],[healthrecord],[healthrecorddate],[sareview],[sareviewdate],[Frail],[frailexplanation],[drappt],[drapptexplanation],[trackingform],[trackingformcorrect],[efguidelines],[ordersinplace],[orderscorrect],[Allergies],[certentries],[certentriesnum],[pc1],[pc1date],[pc2],[pc2date],[pc3],[pc3date],[pc4],[pc4date],[pc5],[pc5date],[pc6],[pc6date],[pc7],[pc7date],[pc8],[pc8date],[logdoccomplete],[logdoccorrect],[prnprotocolscomplete],[prnprotocolscorrect],[numprnprotocols],[cmedslist],[cmedslistwasted],[cmedslistaccurate],[selfadmincapable],[selfadminevaldate],[medslocked],[otcforms],[otcnum],[permitadmindate],[epwaiverdate],[numerrors],[Notes] ) _
                VALUES (@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13,@v14,@v15,@v16,@v17,@v18,@v19,@v20,@v21,@v22,@v23,@v24, @v25,@v26,@v27,@v28,@v29,@v30,@v31,@v32,@v33,@v34,@v35,@v36,@v37,@v38,@v39,@v40,@v41,@v42,@v43,@v44,@v45,@v46,@v47,@v48,@v49,@v50,@v51,@v52,@v53,@v54,@v55,@v56,@v57,@v58);")

应该是这样的:

Access.ExecQuery("INSERT INTO tblQA ([Program],[assessdate],[Reviewer],[healthassess],[healthassessdate],[Screening],[screeningdate],[healthindicators],[healthindicatorsdate],[healthrecord],[healthrecorddate],[sareview],[sareviewdate],[Frail],[frailexplanation],[drappt],[drapptexplanation],[trackingform],[trackingformcorrect],[efguidelines],[ordersinplace],[orderscorrect],[Allergies],[certentries],[certentriesnum],[pc1],[pc1date],[pc2],[pc2date],[pc3],[pc3date],[pc4],[pc4date],[pc5],[pc5date],[pc6],[pc6date],[pc7],[pc7date],[pc8],[pc8date],[logdoccomplete],[logdoccorrect],[prnprotocolscomplete],[prnprotocolscorrect],[numprnprotocols],[cmedslist],[cmedslistwasted],[cmedslistaccurate],[selfadmincapable],[selfadminevaldate],[medslocked],[otcforms],[otcnum],[permitadmindate],[epwaiverdate],[numerrors],[Notes])" & _
                 "VALUES (@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13,@v14,@v15,@v16,@v17,@v18,@v19,@v20,@v21,@v22,@v23,@v24,@v25,@v26,@v27,@v28,@v29,@v30,@v31,@v32,@v33,@v34,@v35,@v36,@v37,@v38,@v39,@v40,@v41,@v42,@v43,@v44,@v45,@v46,@v47,@v48,@v49,@v50,@v51,@v52,@v53,@v54,@v55,@v56,@v57,@v58);")

大约从 2008 年开始,VB 在大多数情况下都不需要行继续字符(那些行本身可能无效的情况)所以你可以这样做:

Access.ExecQuery("INSERT INTO tblQA ([Program],[assessdate],[Reviewer],[healthassess],[healthassessdate],[Screening],[screeningdate],[healthindicators],[healthindicatorsdate],[healthrecord],[healthrecorddate],[sareview],[sareviewdate],[Frail],[frailexplanation],[drappt],[drapptexplanation],[trackingform],[trackingformcorrect],[efguidelines],[ordersinplace],[orderscorrect],[Allergies],[certentries],[certentriesnum],[pc1],[pc1date],[pc2],[pc2date],[pc3],[pc3date],[pc4],[pc4date],[pc5],[pc5date],[pc6],[pc6date],[pc7],[pc7date],[pc8],[pc8date],[logdoccomplete],[logdoccorrect],[prnprotocolscomplete],[prnprotocolscorrect],[numprnprotocols],[cmedslist],[cmedslistwasted],[cmedslistaccurate],[selfadmincapable],[selfadminevaldate],[medslocked],[otcforms],[otcnum],[permitadmindate],[epwaiverdate],[numerrors],[Notes])" &
                 "VALUES (@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13,@v14,@v15,@v16,@v17,@v18,@v19,@v20,@v21,@v22,@v23,@v24,@v25,@v26,@v27,@v28,@v29,@v30,@v31,@v32,@v33,@v34,@v35,@v36,@v37,@v38,@v39,@v40,@v41,@v42,@v43,@v44,@v45,@v46,@v47,@v48,@v49,@v50,@v51,@v52,@v53,@v54,@v55,@v56,@v57,@v58);")

在 VB 的更新版本中(我认为是从 2017 年开始,但也许是 2015 年),也支持多行 String 文字,因此您可以这样做:

Access.ExecQuery("INSERT INTO tblQA ([Program],[assessdate],[Reviewer],[healthassess],[healthassessdate],[Screening],[screeningdate],[healthindicators],[healthindicatorsdate],[healthrecord],[healthrecorddate],[sareview],[sareviewdate],[Frail],[frailexplanation],[drappt],[drapptexplanation],[trackingform],[trackingformcorrect],[efguidelines],[ordersinplace],[orderscorrect],[Allergies],[certentries],[certentriesnum],[pc1],[pc1date],[pc2],[pc2date],[pc3],[pc3date],[pc4],[pc4date],[pc5],[pc5date],[pc6],[pc6date],[pc7],[pc7date],[pc8],[pc8date],[logdoccomplete],[logdoccorrect],[prnprotocolscomplete],[prnprotocolscorrect],[numprnprotocols],[cmedslist],[cmedslistwasted],[cmedslistaccurate],[selfadmincapable],[selfadminevaldate],[medslocked],[otcforms],[otcnum],[permitadmindate],[epwaiverdate],[numerrors],[Notes])
VALUES (@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13,@v14,@v15,@v16,@v17,@v18,@v19,@v20,@v21,@v22,@v23,@v24,@v25,@v26,@v27,@v28,@v29,@v30,@v31,@v32,@v33,@v34,@v35,@v36,@v37,@v38,@v39,@v40,@v41,@v42,@v43,@v44,@v45,@v46,@v47,@v48,@v49,@v50,@v51,@v52,@v53,@v54,@v55,@v56,@v57,@v58);")

SQL 只是忽略换行符和空格所以,如果你喜欢对齐,你也可以这样做:

Access.ExecQuery("INSERT INTO tblQA ([Program],[assessdate],[Reviewer],[healthassess],[healthassessdate],[Screening],[screeningdate],[healthindicators],[healthindicatorsdate],[healthrecord],[healthrecorddate],[sareview],[sareviewdate],[Frail],[frailexplanation],[drappt],[drapptexplanation],[trackingform],[trackingformcorrect],[efguidelines],[ordersinplace],[orderscorrect],[Allergies],[certentries],[certentriesnum],[pc1],[pc1date],[pc2],[pc2date],[pc3],[pc3date],[pc4],[pc4date],[pc5],[pc5date],[pc6],[pc6date],[pc7],[pc7date],[pc8],[pc8date],[logdoccomplete],[logdoccorrect],[prnprotocolscomplete],[prnprotocolscorrect],[numprnprotocols],[cmedslist],[cmedslistwasted],[cmedslistaccurate],[selfadmincapable],[selfadminevaldate],[medslocked],[otcforms],[otcnum],[permitadmindate],[epwaiverdate],[numerrors],[Notes])
                  VALUES (@v1,@v2,@v3,@v4,@v5,@v6,@v7,@v8,@v9,@v10,@v11,@v12,@v13,@v14,@v15,@v16,@v17,@v18,@v19,@v20,@v21,@v22,@v23,@v24,@v25,@v26,@v27,@v28,@v29,@v30,@v31,@v32,@v33,@v34,@v35,@v36,@v37,@v38,@v39,@v40,@v41,@v42,@v43,@v44,@v45,@v46,@v47,@v48,@v49,@v50,@v51,@v52,@v53,@v54,@v55,@v56,@v57,@v58);")