问题描述
我正在尝试使用客户端访问 ODBC 驱动程序使用以下代码从 .NET 对 DB2 数据库运行参数化查询:
I am attempting to run a parameterized query against a DB2 database from .NET using the Client Access ODBC Driver using the following code:
var db2Cmd = new OdbcCommand("INSERT INTO presnlats (LAT) VALUES (@LAT)", db2Conn);
db2Cmd.Parameters.AddWithValue("@LAT", insertValue);
Console.Out.WriteLine(db2Cmd.ExecuteNonQuery());
执行时,抛出OdbcException:
错误 [42S22] [IBM][iSeries Access ODBC 驱动程序][DB2 UDB]SQL0206 - 列 @LAT 不在指定表中.
ERROR [42S22] [IBM][iSeries Access ODBC Driver][DB2 UDB]SQL0206 - Column @LAT not in specified tables.
互联网似乎暗示客户端访问 ODBC 驱动程序支持参数化查询,但此错误似乎另有说明.提供的代码有什么问题吗?
The internets seem to imply that parameterized queries are supported by the client access ODBC driver, but this error seems to indicate otherwise. Is there anything wrong with the supplied code?
推荐答案
你用过吗?作为占位符而不是@LAT?
Have you tried using ? as the placeholder instead of @LAT?
var db2Cmd = new OdbcCommand("INSERT INTO presnlats (LAT) VALUES (?)", db2Conn);
db2Cmd.Parameters.AddWithValue("LAT", insertValue);
Console.Out.WriteLine(db2Cmd.ExecuteNonQuery());
这是 MS Access 在使用 OdbcConnection/OdbcCommand 时所需要的.
This is what MS Access requires when using OdbcConnection / OdbcCommand.
您只需要确保您的 Parameters.AddWithValue() 语句与 INSERT 语句中的字段列表的顺序相同.传递给 AddWithValue() 的第一个参数似乎无关紧要,尽管按照惯例,我将其与字段名称相同.
You just need to make sure your Parameters.AddWithValue() statements are in the same order as the field list in the INSERT statement. First parameter passed to AddWithValue() doesn't seem to matter, although by convention I make it the same as the field name.
这篇关于来自 .NET 的参数化 DB2 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)