【问题标题】:Why I obtain this error message when I try to execute this insert query?为什么我在尝试执行此插入查询时收到此错误消息?
【发布时间】:2014-04-17 14:17:12
【问题描述】:

我对在 Microsoft SQL Server DB 上的表中执行 insert 查询的方法有一些问题。

所以我有这个方法:

public bool insertVulnerabilityAlertDocument_Cpe(long currentNVDVulnId, long cpeId)
{

        System.Data.Common.DbCommand command;
        command = _connection.CreateCommand();

        //long newId = -1;

        _strSQL = "INSERT INTO VulnerabilityAlertDocument_Cpe ([VulnerabilityAlertDocumentId] , [CpeId], [DateAdded] ) VALUES ( @VULNERABILITYALERTDOCUMENTID , @CPEID, GETDATE() )";
        addParameter(command, " @VULNERABILITYALERTDOCUMENTID ", int.Parse(currentNVDVulnId.ToString()));
        addParameter(command, " @CPEID ", int.Parse(cpeId.ToString()));
        command.CommandText = _strSQL;

        _executeNoQuery(command);

        return true;

 }

问题是当尝试执行此查询时,我得到以下异常:

  • ex {"ExecuteNonQuery terminato con errori。\r\nINSERT INTO VulnerabilityAlertDocument_Cpe ([VulnerabilityAlertDocumentId] , [CpeId],[DateAdded])值(@VULNERABILITYALERTDOCUMENTID, @CPEID, GETDATE() )\r\n附近有不正确的语法 '@VULNERABILITYALERTDOCUMENTID'。\r\n必须声明标量变量 \"@VULNERABILITYALERTDOCUMENTID\"."} System.Exception {MyManagerCSharp.MyException}

具体的问题可能是什么?我能做些什么来解决它?

Tnx

【问题讨论】:

  • 尝试删除参数名称中的前导和尾随空格。例如,"@VULNERABILITYALERTDOCUMENTID" 而不是 " @VULNERABILITYALERTDOCUMENTID "。

标签: c# asp.net .net sql-server sql-server-2012


【解决方案1】:

删除" VULNERABILITYALERTDOCUMENTID " 和" @CPEID " 中的多余空格。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    • 2015-10-09
    • 1970-01-01
    • 2020-06-14
    • 2022-01-08
    • 1970-01-01
    相关资源
    最近更新 更多