【问题标题】:Why would error say Column 'n' does not belong to table when it clearly does?为什么错误会说 Column 'n' 不属于 table 而它显然是?
【发布时间】:2014-10-27 21:00:11
【问题描述】:

我正在 Microsoft Access 数据库上运行来自 ASP.NET 的查询。错误状态:列 'Area1' 不属于表。

看起来错误发生在这里:

    cmd.Parameters.AddWithValue("@" + columnName, progressRow[columnName]);

sql 命令如下所示:

Extract.exe 警告:0 : 03/09/2014 10:48:28 | CSU 公用事业 |塞伦盖蒂 |添加查询 : INSERT INTO 属性 (Address1,Address2,Address3,Address4,Area1,Area10,Area11,Area12,Area13,Area14,Area15,Area16,Area17,Area18,Area19,Area2,Area20,Area3,Area4,Area5,Area6,Area7 ,Area8,Area9,BlockFlag,CapitalValue,ConstructionYear,CurrentStock,Department,DepartmentFIS,DisposalDate,DisposalReason,DoubleBeds,DwellingType,DwellingTypeCode,EastingGridRef,ElevationGridRef,HeatingCode,HouseNumber,KeyBlockProperty,KeyCurrTcyId,KeyProperty,KeyPropertyTypeCode,KeyStreet,LocalPerm,NorthingGridRef,O ,Postcode,PropertyClassCode,PropertyGroup,QLX,RepairResponsibility,RiskLevel,RTBCode,SingleBeds,StatPerm,Suffix,Telephone,TenureCode,UserCode,Void,WardCode,WaterCode,UpdateFlag) 值 (?,?,?,?,?,?,? ,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ,?,?,?,?,?,?,?)

Area1 在设计视图中明确定义为短文本字段。

我手动运行了以下测试并且它有效:

    INSERT INTO Property (Address1,Address2,Address3,Address4,Area1) VALUES ('Test1','Test','Test','Test','Test')

它在玩什么?

【问题讨论】:

  • 我的错误。错误来自完全不同的地方 - progressRow [columnName]。通过添加以下内容找到它: if (!progressRow.Table.Columns.Contains(columnName)) { TraceFunctions.WarningMessage("Error " + columnName + " does not exist in datarow."); }

标签: ms-access


【解决方案1】:

它可能会混淆命名参数与列名相同(我以前见过,但不记得是哪个引擎)。尝试将值添加参数的函数更改为“@x”+列名...这样,OleDb 驱动程序就不会尝试寻找与@Area1 匹配的列Area1,而是寻找@xArea1(同样其余的)。

另一种可能性是您也插入的数据。可能有一些特殊字符,如“@”或“?”或类似的领域使帖子混淆?

【讨论】:

    猜你喜欢
    • 2011-12-22
    • 2021-07-23
    • 1970-01-01
    • 2021-10-21
    • 1970-01-01
    • 2020-08-04
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    相关资源
    最近更新 更多