“必须声明变量@ myvariable” ADO参数化查询出错 [英] "Must declare the variable @myvariable" error with ADO parameterized query

查看:395
本文介绍了“必须声明变量@ myvariable” ADO参数化查询出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ADO的参数化查询。执行命令对象抛出错误:

i am trying to use parameterized queries with ADO. Executing the Command object throws the error:


必须声明变量'@filename '

Must declare the variable '@filename'

我使用声明参数 @filename CreateParameter / Append

i declare the parameter @filename using CreateParameter/Append:

sql := 'INSERT INTO Sqm(Filename, data) VALUES(@filename, @data)';

command := CoCommand.Create;
command.Set_ActiveConnection(Connection.ConnectionObject);
command.Set_CommandText(sql);
command.Set_CommandType(adCmdText);
command.Parameters.Append(Command.CreateParameter('@filename', adLongVarWChar, adParamInput, -1, Filename));
command.Parameters.Append(Command.CreateParameter('@data', adLongVarWChar, adParamInput, -1, xml);

command.Execute({out}recordsAffected, EmptyParam, adCmdText or adExecuteNoRecords);

我做错了什么?

推荐答案

到目前为止,我知道ADO不支持SQL语句(SELECT,INSERT,UPDATE)中的命名参数,所以你必须使用? c $ c> char表示参数

As far i know ADO doesn't supports named parameters in SQL sentences (SELECT, INSERT, UPDATE), so you must use the ? char to indicate the parameter

sql := 'INSERT INTO Sqm(Filename, data) VALUES(?, ?)';

然后按照与sql语句中使用的顺序分配参数值。

and then assign the parameters values in the same order as are used in the sql sentence.

ADO 2.6推出 NamedParameters 属性,但它似乎只适用于存储过程。

ADO 2.6 Introduces the NamedParameters property, but it seems which only works with stored procedures.

这篇关于“必须声明变量@ myvariable” ADO参数化查询出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆