我的 SQL 插入错误在哪里?

Posted

技术标签:

【中文标题】我的 SQL 插入错误在哪里?【英文标题】:Where is my SQL Insert Error? 【发布时间】:2015-03-26 00:57:03 【问题描述】:

我正在尝试通过 .Net Framework 中的 c# 修改 Microsoft Access 数据库中的记录。这是我的执行代码,但我不断从我的 INSERT 语句中收到语法错误,无法弄清楚为什么,有人可以帮忙吗?我也遇到了一些麻烦,其中 SELECT 语句没有返回我知道数据库中存在的任何数据。我已经为此工作了好几天,需要一双新的眼睛,我做错了什么?

这是错误:

错误:System.Data.OleDb.OleDbException (0x80040E14):INSERT INTO 语句中的语法错误。在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) 在 System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) 在 System.Data。在 System.Data.OleDb.OleDb.OleDbCommand.ExecuteNonQuery() 在 ABM_Office_System.UpdateABMDatabaseWindow.b__0() 的 System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior 行为,字符串方法) 的 OleDb.OleDbCommand.ExecuteCommand(CommandBehavior 行为,对象和 executeResult)。 ..

for (int i = 0; i < hmuFinalList.Count; i++)

    Dispatcher.Invoke(() =>
    
        stsW.StatusLbl.Content = "Updating " + hmuFinalList[i].MName + "'s records";
    );
    readcmd.Parameters.Clear();
    readcmd.CommandText = "SELECT * FROM [ABM] WHERE [M Name]=@";
    readcmd.Parameters.AddWithValue("@", hmuFinalList[i].MName);
    Console.WriteLine("READCMD: " + readcmd.CommandText);
    Console.WriteLine("ReadcmdTRANSACTION: ");
    affected = readcmd.ExecuteNonQuery();
    Console.WriteLine("affected: " + affected.ToString());
    if (affected > 0) //UPDATE TIME!
    
        executecmd.Parameters.Clear();
        executecmd.CommandText = "UPDATE [ABM] SET "+
        "[M Type]=@," +
        "[M Component]=@," +
        "[M Birth Date]=@," +
        "[M Visa Expiration Date]=@," +
        "[M Residence Nation]=@," +
        "[M MTC]=@," +
        "[M MTC Date]=@," +
        "[M Arrival Date]=@," +
        "[M Release Date]=@, " +
        "[M Past Position]=@," +
        "[M Past Position Start Date]=@," +
        "[M Current Position Start Date]=@," +
        "[M Past Area]=@," +
        "[M Past Area Start Date],=@" +
        "[M Current Area Start Date]=@," +
        "[M Title - English]=@," +
        "[M Title - Non-English]=@," +
        "[M HMU Correspondent Type]=@," +
        "[M HMU Correspondent Last Name]=@," +
        "[M HMU Correspondent Given Name]=@," +
        "[M HMU Correspondent Language]=@," +
        "[M HMU Correspondent Comment]=@," +
        "[M HMU Correspondent Title]=@," +
        "[M HMU Correspondent Relationship]=@," +
        "[M HMU Correspondent Pronoun - Subject]=@," +
        "[M HMU Correspondent Pronoun - Object]=@," +
        "[M HMU Correspondent Pronoun - Possessive]=@," +
        "[M HMU Correspondent Pronoun - Other]=@," +
        "[M Previous Address Line 1]=@," +
        "[M Previous Address City]=@," +
        "[M Previous Address State/Province]=@,"
        + "[M Previous Address Postal Code]=@," +
        "[M Previous Address Country]=@," +
        "[M Type Plural]=@," +
        "[M Transfer Effective Date]=@," +
        "[M Position is a Promotion]=@," +
        "[M HMU Correspondent Pronoun Cap - Subject]=@," +
        "[M HMU Correspondent Pronoun Cap - Object]=@," +
        "[M HMU Correspondent Pronoun Cap - Possessive]=@," +
        "[M HMU Correspondent Pronoun Cap - Other]=@," +
        "[M HMU Correspondent Title - Envelope]=@," +
        "[M Where Born]=@" +
        "WHERE [M Name]=@";

        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MType) ? (object)DBNull.Value : hmuFinalList[i].MType);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MComponent) ? (object)DBNull.Value : hmuFinalList[i].MComponent);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MBirthDate) ? (object)DBNull.Value : hmuFinalList[i].MBirthDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MVisaExpirationDate) ? (object)DBNull.Value : hmuFinalList[i].MVisaExpirationDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MResidenceNation) ? (object)DBNull.Value : hmuFinalList[i].MResidenceNation);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MMTC) ? (object)DBNull.Value : hmuFinalList[i].MMTC);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MMTCDate) ? (object)DBNull.Value : hmuFinalList[i].MMTCDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MArrivalDate) ? (object)DBNull.Value : hmuFinalList[i].MArrivalDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MReleaseDate) ? (object)DBNull.Value : hmuFinalList[i].MReleaseDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPastPosition) ? (object)DBNull.Value : hmuFinalList[i].MPastPosition);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPastPositionStartDate) ? (object)DBNull.Value : hmuFinalList[i].MPastPositionStartDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MCurrentPositionStartDate) ? (object)DBNull.Value : hmuFinalList[i].MCurrentPositionStartDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPastArea) ? (object)DBNull.Value : hmuFinalList[i].MPastArea);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPastAreaStartDate) ? (object)DBNull.Value : hmuFinalList[i].MPastAreaStartDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MCurrentAreaStartDate) ? (object)DBNull.Value : hmuFinalList[i].MCurrentAreaStartDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MTitleEnglish) ? (object)DBNull.Value : hmuFinalList[i].MTitleEnglish);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MTitleNonEnglish) ? (object)DBNull.Value : hmuFinalList[i].MTitleNonEnglish);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentType) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentType);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentLastName) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentLastName);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentGivenName) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentGivenName);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentLanguage) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentLanguage);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentComment) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentComment);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentTitle) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentTitle);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentRelationship) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentRelationship);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounSubject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounSubject);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounObject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounObject);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounPossessive) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounPossessive);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounOther) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounOther);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressLine1) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressLine1);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressCity) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressCity);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressStateProvince) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressStateProvince);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressPostalCode) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressPostalCode);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressCountry) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressCountry);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MTypePlural) ? (object)DBNull.Value : hmuFinalList[i].MTypePlural);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MTransferEffectiveDate) ? (object)DBNull.Value : hmuFinalList[i].MTransferEffectiveDate);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MPositionisaPromotion) ? (object)DBNull.Value : hmuFinalList[i].MPositionisaPromotion);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapSubject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapSubject);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapObject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapObject);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapPossessive) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapPossessive);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapOther) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapOther);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].CorrespondentTitleEnvelope) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentTitleEnvelope);
        executecmd.Parameters.AddWithValue("@", string.IsNullOrEmpty(hmuFinalList[i].MWhereBorn) ? (object)DBNull.Value : hmuFinalList[i].MWhereBorn);
        executecmd.Parameters.AddWithValue("@", hmuFinalList[i].MName);
        Console.WriteLine("HMU UPDATE EXECUTION: " + executecmd.CommandText);
        executecmd.ExecuteNonQuery();
    
    else //INSERT TIME!
    
        executecmd.Parameters.Clear();
        executecmd.CommandText = "INSERT INTO [ABM] ([M Name],[M Type],[M Component],[M Birth Date],[M Visa Expiration Date],[M Residence Nation],"+
        "[M MTC]," +
        "[M MTC Date],"+
        "[M Arrival Date],"+
        "[M Release Date], "+
        "[M Past Position],"+
        "[M Past Position Start Date]," +
        "[M Current Position Start Date]," +
        "[M Past Area],"+
        "[M Past Area Start Date],"+
        "[M Current Area Start Date],"+
        "[M Title - English],"+
        "[M Title - Non-English],"+
        "[M HMU Correspondent Type],"+
        "[M HMU Correspondent Last Name]," +
        "[M HMU Correspondent Given Name]," +
        "[M HMU Correspondent Language]," +
        "[M HMU Correspondent Comment]," +
        "[M HMU Correspondent Title]," +
        "[M HMU Correspondent Address Line 1]," +
        "[M HMU Correspondent Relationship]," +
        "[M HMU Correspondent Pronoun - Subject]," +
        "[M HMU Correspondent Pronoun - Object]," +
        "[M HMU Correspondent Pronoun - Possessive]," +
        "[M HMU Correspondent Pronoun - Other]," +
        "[M Previous Address Line 1],"+
        "[M Previous Address City]," +
        "[M Previous Address State/Province],"+
        "[M Previous Address Postal Code]," +
        "[M Previous Address Country],"+
        "[M Type Plural]," +
        "[M Transfer Effective Date],"+
        "[M Position is a Promotion]," +
        "[M HMU Correspondent Pronoun Cap - Subject]," +
        "[M HMU Correspondent Pronoun Cap - Object]," +
        "[M HMU Correspondent Pronoun Cap - Possessive]," +
        "[M HMU Correspondent Pronoun Cap - Other]," +
        "[M HMU Correspondent Title - Envelope]," +
        "[M Where Born],)"+
        "VALUES(@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@,@)";
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MName) ? (object)DBNull.Value : hmuFinalList[i].MName);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MType) ? (object)DBNull.Value : hmuFinalList[i].MType);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MComponent) ? (object)DBNull.Value : hmuFinalList[i].MComponent);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MBirthDate) ? (object)DBNull.Value : hmuFinalList[i].MBirthDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MVisaExpirationDate) ? (object)DBNull.Value : hmuFinalList[i].MVisaExpirationDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MResidenceNation) ? (object)DBNull.Value : hmuFinalList[i].MResidenceNation);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MMTC) ? (object)DBNull.Value : hmuFinalList[i].MMTC);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MMTCDate) ? (object)DBNull.Value : hmuFinalList[i].MMTCDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MArrivalDate) ? (object)DBNull.Value : hmuFinalList[i].MArrivalDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MReleaseDate) ? (object)DBNull.Value : hmuFinalList[i].MReleaseDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPastPosition) ? (object)DBNull.Value : hmuFinalList[i].MPastPosition);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPastPositionStartDate) ? (object)DBNull.Value : hmuFinalList[i].MPastPositionStartDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MCurrentPositionStartDate) ? (object)DBNull.Value : hmuFinalList[i].MCurrentPositionStartDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPastArea) ? (object)DBNull.Value : hmuFinalList[i].MPastArea);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPastAreaStartDate) ? (object)DBNull.Value : hmuFinalList[i].MPastAreaStartDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MCurrentAreaStartDate) ? (object)DBNull.Value : hmuFinalList[i].MCurrentAreaStartDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MTitleEnglish) ? (object)DBNull.Value : hmuFinalList[i].MTitleEnglish);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MTitleNonEnglish) ? (object)DBNull.Value : hmuFinalList[i].MTitleNonEnglish);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentType) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentType);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentLastName) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentLastName);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentGivenName) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentGivenName);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentLanguage) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentLanguage);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentComment) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentComment);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentTitle) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentTitle);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentAddressLine1) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentAddressLine1);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentRelationship) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentRelationship);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounSubject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounSubject);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounObject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounObject);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounPossessive) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounPossessive);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounOther) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounOther);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressLine1) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressLine1);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressCity) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressCity);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressStateProvince) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressStateProvince);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressPostalCode) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressPostalCode);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPreviousAddressCountry) ? (object)DBNull.Value : hmuFinalList[i].MPreviousAddressCountry);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MTypePlural) ? (object)DBNull.Value : hmuFinalList[i].MTypePlural);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MTransferEffectiveDate) ? (object)DBNull.Value : hmuFinalList[i].MTransferEffectiveDate);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MPositionisaPromotion) ? (object)DBNull.Value : hmuFinalList[i].MPositionisaPromotion);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapSubject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapSubject);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapObject) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapObject);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapPossessive) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapPossessive);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentPronounCapOther) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentPronounCapOther);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].CorrespondentTitleEnvelope) ? (object)DBNull.Value : hmuFinalList[i].CorrespondentTitleEnvelope);
        executecmd.Parameters.AddWithValue("@",string.IsNullOrEmpty(hmuFinalList[i].MWhereBorn) ? (object)DBNull.Value : hmuFinalList[i].MWhereBorn);
        Console.WriteLine("HMU INSERT EXECUTION: " + executecmd.CommandText);
        executecmd.ExecuteNonQuery();
    


这快把我逼疯了!

【问题讨论】:

最后一行多了一个逗号:[M Where Born],) 我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。 当我遇到复杂的 SQL 语句时,我通常会收集程序执行之前创建的最终 sql 字符串,并尝试直接在数据库中运行它。有时这样会使错误更加清晰。 这段代码很适合使用 ORM 我不太记得了。在执行cmd.ExecuteNonQuery 的行上放置一个断点。到达那里后,将鼠标悬停在 executecmd 上,并探索其属性,直到找到 sql 值。 (如果您愿意,也可以查看即时窗口或监视窗口) 【参考方案1】:

您的插入列列表不应该以逗号结尾。

替换

        "[M Where Born],)"+

        "[M Where Born])"+

【讨论】:

以上是关于我的 SQL 插入错误在哪里?的主要内容,如果未能解决你的问题,请参考以下文章

Oracle SQL 中的插入选择查询缺少表达式错误

SQL插入查询不按按钮存储

php, phpMyAdmin sql 错误

将日期插入数据库时​​出现 SQL 语法错误(框架:codeigniter)

SQL插入语句语法错误VB.net

带有内部联接的 SQL 插入试图插入错误的列