有一个存储过程:
create procedure chaxunproc
@name varchar(50), //对应字段名
@contents varchar(50) //对应查询内容
as
declare @s1 varchar(200)
set @sl='select * from table where '+@name+'like'''+@contents+''''//这一句这样写对不对?
exec @sl
if exists(@s1) 判断查询的内容是否存在。同时请问这样写法是否正确?
print 'ok' //如果找到,显示OK。其实我想在这一句去改变dbgrid或STRINGGRID查找到的记录的颜色,可不可以?
else
print 'no find'在DELPHI中调用adostoredproc1
with adostoredproc1 do
begin
parameters[0].value:=combobox1.text;
parameters[1].value:=edit1.text;
parameters.ParamByName('@name').asstring:=combox1.text;
parameters.ParamByName('@contents').asstring:=edit1.text;
open;
end;
create procedure chaxunproc
@name varchar(50), //对应字段名
@contents varchar(50) //对应查询内容
as
declare @s1 varchar(200)
set @sl='select * from table where '+@name+'like'''+@contents+''''//这一句这样写对不对?
exec @sl
if exists(@s1) 判断查询的内容是否存在。同时请问这样写法是否正确?
print 'ok' //如果找到,显示OK。其实我想在这一句去改变dbgrid或STRINGGRID查找到的记录的颜色,可不可以?
else
print 'no find'在DELPHI中调用adostoredproc1
with adostoredproc1 do
begin
parameters[0].value:=combobox1.text;
parameters[1].value:=edit1.text;
parameters.ParamByName('@name').asstring:=combox1.text;
parameters.ParamByName('@contents').asstring:=edit1.text;
open;
end;
解决方案 »
- 我想要实现这样的功能,请问delphi应该从哪里开始学?
- 大家帮我女儿取个好名字!
- 招聘Delphi高手
- ACCESS数据库两个表关联问题
- 如何计算2的N次幂的结果,代码怎么实现???
- 怎样增加TCheckListBox带左面的下拉条和底部的水平拉条的属性?
- 关于拖放的问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 请教我写了个DEPHI的程序,我想把它编译成脱离环境的可执行文件,我应该怎么操作,
- 子鱼求救:怎样才能使用dbgrid中的数据进行计算?
- 高难度问题!!!如何在stringgrid网格中输入汉字,高分悬赏(130分),高手请进!!!
- IGMP 数据包如何发送?
- 如何将数据集中的数据导入EXCEL中
CREATE procedure chaxunproc
@name varchar(50), --//对应字段名
@contents varchar(50) --//对应查询内容
as
declare @sl varchar(200) --//注意@sl与@s1的区别
set @sl="select * from table where "+@name+" like '%"+@contents+"%'"--//这一句这样写,注意空格
exec(@sl)
if @@rowcount>=1 --//判断查询的内容是否存在。大于或等于1则表示有记录
print 'ok' --//如果找到,显示OK。
else
print 'no find'
连这一句都通不过呀,难过
set @sl='select * from table where '''+@name
+''' like ''%'+@contents+'%'''
绝对能搞定!
+''' like ''%'+@contents+'%'''
这一步有希望了.....
请朋友们看看错在什么地方?
stringgrid1.rowcount:=adostoredproc1.recordcount+1;
stringgrid1.colcount:=adostoredproc1.fields.count;
for q:=0 to adostoredproc1.fieldcount-1 do
stringgrid1.cell[q,0]:=adostoredproc1.fields[q].fieldname;//显示字段名
n:=1; 下面是希望能显示出用存储过程查到的记录。但是没有显示。请问错在哪里?
while not adostoredproc1.eof do
begin
for m:=0 to stringgrid1.colcount-1 do
begin
stringgrid1.cells[m,n]:=adostoredproc1.fields[m].asstring;
end;
adostoredproc1.next;
inc(n);
var
q,n,m:integer;
begin
stringgrid1.rowcount:=adostoredproc1.recordcount+1;
stringgrid1.colcount:=adostoredproc1.FieldCount;
for q:=0 to adostoredproc1.fieldcount-1 do
stringgrid1.cells[q,0]:=adostoredproc1.fields[q].fieldname;//显示字段名
n:=1;
adostoredproc1.First; //定位到第一条
while not adostoredproc1.eof do
begin
for m:=0 to adostoredproc1.fieldcount-1 do
begin
stringgrid1.cells[m,n]:=adostoredproc1.fields[m].asstring;
end;
adostoredproc1.next;
inc(n);
end;
end;
不就是少了空格,我好像告诉过你了请大家去 http://www.new7wonders.com/c/voting.php 投长城一票
@name varchar(50), --//对应字段名
@contents varchar(50) --//对应查询内容
as
declare @sl varchar(200)
set @s1='select * from table where '''+@name+''' like '' %'+@contents+'%'''
exec(@sl)
用ADOSTORED调用时又说不认识参数@name.到底是怎么回事?
' like ''%'+@contents+'%'''