當然有啦
你用SQL語句查詢出一長串
如:
declare @value
set @value=''
select @value=@value+field1+',' from (select distinct field1 from tablename) A
set @value=left(@value,len(@value)-1)
select @value
我这段代码那里有问题啊!怎么运行没反映哦!!
那位高手帮忙看看哦!
procedure TForm3.FormShow(Sender: TObject);
begin
dm1.ADOQuery1.Close;
dm1.ADOQuery1.SQL.Clear;
dm1.ADOQuery1.SQL.text :='select jfjs_bh from jqjs';
dm1.ADOQuery1.Open;
combobox1.items.clear;
while dm1.ADOQuery1.Eof do
begin
combobox1.items.add(dm1.adoquery1.fieldbyname('jfjs_bh').asstring);
dm1.ADOQuery1.Next;
end;
end;
是adotable 楼下说的对,都一样用,adoquery这样
combobox2.Items.Clear;
with adoquery1 do
begin
close;
sql.clear;
sql.add('select * from student');
open;
while (not adoquery1.Eof) do
begin
str:=adoquery1['stucode'];
if VarIsNull(str) then
adoquery1.Next
else
begin
combobox2.Items.Add(str);
adoquery1.Next;
end;
end;
这是把student表中的stucode加到combobox2中
begin
datamodulefm.at_student_add.Filtered:=false;
datamodulefm.at_student_add.Open;
datamodulefm.at_student_add.First;
combobox2.Items.Clear;
while (not datamodulefm.at_student_add.Eof) do
begin
str:=datamodulefm.at_student_add.fieldbyname('stucode').Value;
if VarIsNull(str) then
datamodulefm.at_student_add.Next
else
begin
combobox2.Items.Add(str);
datamodulefm.at_student_add.Next;
end;
ComboBox1.Items.Clear;
with AdoQuery do
Try
Close;
SQL.Text := 'Select Distinct Field1 from tablename';
Open;
if IsEmpty then Exit;
while Not Eof do
begin
if adoquery1.fieldsbuname('fields1').asstring<>'' then //---去掉空值
ComboBox1.Items.Add(AdoQuery1.FieldByName('Field1').AsString);
Next;
end;
except
ShowMessage('出錯信息');
end;
ComboBox1.Items.Update;
关注一下
ComboBox1.Items.Clear;
with AdoQuery do
Try
Close;
SQL.Text := 'Select Distinct Field1 from tablename';
Open;
if IsEmpty then Exit;
while Not Eof do
begin
ComboBox1.Items.Add(AdoQuery1.FieldByName('Field1').AsString);
Next;
end;
except
ShowMessage('出錯信息');
end;
ComboBox1.Items.Update;
我用
procedure TForm3.ComboBox1KeyPress(Sender: TObject; var Key: Char);
begin
dm1.ADOQuery1.SQL.Text:='select * from jqjs where jfjs_bh='''+combobox1.Text+'''';
dm1.ADOQuery1.Open;
end;
显示combobox1选中的数据库中的数据。可是为什么没反映呢?
procedure TForm1.FormCreate(Sender: TObject);
var
i:integer;
begin
for i:=0 to (query1.FieldCount-1) do
begin
combobox1.Items.Add(query1.Fields[i].FieldName);
end;
end;