定义了一个动态数组,我的代码如下,可是我的代码只能把数据库第一列写入数组,请问在不编写存储过程的情况下怎样实现标题的功能?把数据库查询的某列的所有结果都写入一个字符串数组
var str:array of string ;
i:integer; htgsmc:string;
begin
i:=0;
htgsmc:=trim(edit1.Text);
with ClientDataSet1 do
begin
close;
commandtext:='select distinct htbhid from [htjlb] where htgsmc like :htgsmc';//不重复的多个记录
params.ParamValues['htgsmc']:=trim(htgsmc);
open;
showmessage(inttostr(recordcount));
SetLength(str,RecordCount);//设置数组长度为查询记录数 while not eof do
begin
if i<RecordCount then
begin
str[i]:=trim(fieldbyname('htbhid').asstring);
showmessage(str[i]);
i:=i+1;
end
end;
end;
end;
var str:array of string ;
i:integer; htgsmc:string;
begin
i:=0;
htgsmc:=trim(edit1.Text);
with ClientDataSet1 do
begin
close;
commandtext:='select distinct htbhid from [htjlb] where htgsmc like :htgsmc';//不重复的多个记录
params.ParamValues['htgsmc']:=trim(htgsmc);
open;
showmessage(inttostr(recordcount));
SetLength(str,RecordCount);//设置数组长度为查询记录数 while not eof do
begin
if i<RecordCount then
begin
str[i]:=trim(fieldbyname('htbhid').asstring);
showmessage(str[i]);
i:=i+1;
end
end;
end;
end;
再说,你的查询结果就只有这么一列啊。照你的方法,只要把你要得到的那列查询一下好了。
begin
str[i]=trim(fieldbyname('htbhid').asstring);
inc(i);
next;
end;
begin
if i <RecordCount then
begin
str[i]:=trim(fieldbyname('htbhid').asstring);
showmessage(str[i]);
next;
i:=i+1;
end
end;