我试图使用客户端访问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不在指定的表中。 / p>
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查询
发布评论