不同数据类型如何传递?(50分)

C

cnnoah

Unregistered / Unconfirmed
GUEST, unregistred user!
参数V1为字符型,现在想把它转换为整型,以实现如下代码:

ADODataSet1.CommandText:='select * from txcs where ZBSD='+P1;

ZBSD为数值型(整型),我怎么把P1的值传递给ZBSD呢?
 
就这样就可以了呀!
 
程序在编译运行后提示:
project Project1.exe raised exception class EOleException with messge
'第1行:'='附近有语法错误。'
 
忘了说P1是String类型
 
是啊,应该可以的,出什么错误信息?
不好意思,刚刚没有看到错误信息。
你是用的是TADODataSet?ZBSD字段是什么类型的?是不是要用
ADODataSet1.CommandText:='select * from txcs where ZBSD='''+P1+'''';
但是似乎这样跟你叙述的不一致
 
var
p1 :string;
把P1设为字符型,不管ZBSD是什么型.
ADODataSet1.CommandText:='select * from txcs where ZBSD='+P1+';
 
可能跟随这段代码没有关系,你检查P1是不是一个有效的整数字符串。
 
to shenloqi
是的我是用的是ADODataSet,ZBSD是数值型,用你的方法,编译提示"将string转换
为numeric出错"。
 
to aizb
是的,我的ZBSD是numeric
 
ADODataSet1.CommandText:=format('select * from txcs where ZBSD=%s',[P1]);
 
to ysai
你的方法也不行
 
to shenloqi
ADODataSet1.CommandText:='select * from txcs where ZBSD='+P1+';
这个方法行了,我把数据类型改过来了。
thx
 
thanks all
 
多人接受答案了。
 
顶部