with ADOQuery1 do
begin
try
Close;
First;
SQL.Add('select count(*) as num from id_word_score where word_score=''a''') ;
Open;
j :=fieldbyname('num').asinteger;
Label1.Caption:=inttostr(j);
我想统计数据库第一条记录中的a的个数 请问上面的语句有什么错哦 ? 或者有什么方法能实现这样的结果
begin
try
Close;
First;
SQL.Add('select count(*) as num from id_word_score where word_score=''a''') ;
Open;
j :=fieldbyname('num').asinteger;
Label1.Caption:=inttostr(j);
我想统计数据库第一条记录中的a的个数 请问上面的语句有什么错哦 ? 或者有什么方法能实现这样的结果
begin
close;
sql.clear;
sql.add('select count(*) as num from id_word_score where word_score=''a''');
open;
end;
if adoquery1.recordcount>0 then
label1.caption:=adoquery1.fieldbyname('num').asstring;
end;
function TForm1.rightpos(ch:char;str:string):integer;
var
i:integer;
begin
result:=0;
for i:=0 to length(s) do
if str[i]=ch then
result:=result+1;
end;procedure TForm1.Button1Click(Sender: TObject);
var
tmp:string;
begin
with adoquery1 do
begin
close;
sql.clear;
sql.add('select word_score from id_word_score ');
open;
end;
if adoquery1.recordcount>0 then
begin
adoquery1.first; //记录集第一条
tmp:=adoquery1.fieldbyname('word_score').asstring;
Label1.Caption:=inttostr(rightpos('a',tmp)); //查找a的个数
end
else
application.message('没有信息!','提示',mb_ok);
end;
出现这个提示
你需要在你的程序代码
private
{ Private declarations }
public
{ Public declarations }这个部分上面加上 function rightpos(ch:char;str:string):integer; 这个函数在rightpos函数中for i:=0 to length(s) do
改成length(str),自己写掉了,忘记改过来了.我都测试过了的,都没问题