无法使用 ADO.NET 创建 Interbase 参数化查询
我正在尝试使用 ADO.NET 向 Interbase XE 数据库发出参数化 SELECT。我正在使用的代码如下:
using (OdbcConnection odbcConnection = new OdbcConnection(ConfigurationManager.ConnectionStrings["LawbaseTest"].ToString()))
{
odbcConnection.Open();
using (OdbcCommand odbcCommand = new OdbcCommand())
{
odbcCommand.CommandType = CommandType.Text;
odbcCommand.Connection = odbcConnection;
odbcCommand.Parameters.Add(new OdbcParameter(":CaseNumber", 1265));
odbcCommand.CommandText = "select * from cmstub where cm_recnum = :CaseNumber";
using (IDataReader rdrData = odbcCommand.ExecuteReader())
{
Output(rdrData["CM_DESC"]);
}
}
}
我收到以下错误:
ERROR [42S22] [DataDirect][ODBC InterBase driver][InterBase]Dynamic SQL Error, SQL error code = -206, Column unknown, CASENUMBER
这表明查询没有按照 Interbase 识别为参数化查询的语法发送到 Interbase。
这比我预想的要难得多。我是菲科吗?你能帮忙吗?
I'm trying to issue a parameterised SELECT to an Interbase XE database using ADO.NET. The code I'm using is as follows:
using (OdbcConnection odbcConnection = new OdbcConnection(ConfigurationManager.ConnectionStrings["LawbaseTest"].ToString()))
{
odbcConnection.Open();
using (OdbcCommand odbcCommand = new OdbcCommand())
{
odbcCommand.CommandType = CommandType.Text;
odbcCommand.Connection = odbcConnection;
odbcCommand.Parameters.Add(new OdbcParameter(":CaseNumber", 1265));
odbcCommand.CommandText = "select * from cmstub where cm_recnum = :CaseNumber";
using (IDataReader rdrData = odbcCommand.ExecuteReader())
{
Output(rdrData["CM_DESC"]);
}
}
}
I'm getting the following error:
ERROR [42S22] [DataDirect][ODBC InterBase driver][InterBase]Dynamic SQL Error, SQL error code = -206, Column unknown, CASENUMBER
Which suggests to me that the query is not being sent to Interbase in a syntax it recognises as a parameterised query.
This is rather harder than I was expecting. Am I being a ficko? Can you help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
命名参数不被广泛支持似乎是常态,您尝试使用吗?相反,即 cm_recnum = :CaseNumber 到 cm_recnum = ?
It seems to be the norm that named parameters aren't supported widely, did you try using ? instead, i.e. cm_recnum = :CaseNumber to cm_recnum = ?