来自.NET的参数化DB2查询

编程入门 行业动态 更新时间:2024-10-23 23:23:34
本文介绍了来自.NET的参数化DB2查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图使用客户端访问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查询

本文发布于:2023-11-16 19:51:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1607225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!