我想将表TWWP中的 MC 添加到ComboBox1中代码如下
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Clear ;
ADOQuery1.Open;
if not ADOQuery1.IsEmpty then
begin
ADOQuery1.First ;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add('select MC from TWWP');
ComboBox1.Text:=ADOQuery1.FieldValues['MC']; //运行提示MC没找到,但表内MC确实存在。如果把这行屏蔽后,能运行,但是ComboBox1下拉菜单中无任何数据。
while not ADOQuery1.Eof do
begin
ComboBox1.Items.Add(ADOQuery1.FieldValues['MC']);
ADOQuery1.next;
end;
end;
ADOQuery1.Close;
end;大家帮忙看看错误在哪啊?
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Clear ;
ADOQuery1.Open;
if not ADOQuery1.IsEmpty then
begin
ADOQuery1.First ;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add('select MC from TWWP');
ComboBox1.Text:=ADOQuery1.FieldValues['MC']; //运行提示MC没找到,但表内MC确实存在。如果把这行屏蔽后,能运行,但是ComboBox1下拉菜单中无任何数据。
while not ADOQuery1.Eof do
begin
ComboBox1.Items.Add(ADOQuery1.FieldValues['MC']);
ADOQuery1.next;
end;
end;
ADOQuery1.Close;
end;大家帮忙看看错误在哪啊?
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Clear ;
with adoquery1 do
begin
close;
sql.clear;
sql.add(''select MC from TWWP');
open;
first;
while not eof do
begin
combobox1.items.add(fieldbyname('MC').value);
next;
end;
end;
combobox1.items.add(ADOQuery1.fieldbyname('MC').value);
另外,你若确定有mc的话
检查adoquery的connection设置是否正确
单步调试
是因为ADOQuery1.SQL.Add('select MC from TWWP')之后,并没有打开数据集,应该要adoquery1.open;2.楼主前面二行代码:
ComboBox1.Items.Clear;
ADOQuery1.Open; //其中这个ADOQuery1.Open,adoquery1都没有SQL语句,OPEN也没有意义,所以这行不需要,数据集没打开,对楼主数据集的操作(IsEmpty/First)都没意义;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Clear ;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add('select MC from TWWP');
ADOQuery1.OPEN;
ADOQuery1.First;
ComboBox1.Text:=ADOQuery1.FieldValues['MC'];
while NOT ADOQuery1.Eof do
begin
ComboBox1.Items.Add(ADOQuery1.FieldValues['MC']);
ADOQuery1.next;
end;
ADOQuery1.Close;
end;
begin
ComboBox1.Items.Clear;
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select distinct MC from TWWP');
Open;
First;
while not eof do
begin
Combobox1.Items.Add(Trim(fieldbyname('MC').value));
Next;
end;
end;
end;