delphi 取sql所有返回值(100分)

  • 主题发起人 主题发起人 csmtools
  • 开始时间 开始时间
C

csmtools

Unregistered / Unconfirmed
GUEST, unregistred user!
如题。 with quer1 do <br>close;<br>SQL.CommaText:='select name from User';<br>Open;<br>First;<br>commbobox.Items.Add(FieldByName('name').AsString);<br>ExecSQL;<br>Close;<br>Cbb_Name.Update;<br>此时,commbobox只有从sql中返回的第一数据。不能全部返回来。就是不知道如何写next <br>请各位帮忙
 
with quer1 do begin<br>&nbsp; &nbsp;close;<br>&nbsp; &nbsp;SQL.CommaText:='select name from User';<br>&nbsp; &nbsp;Open;<br>&nbsp; &nbsp;First;<br>&nbsp; &nbsp;while not eof do begin<br>&nbsp; &nbsp; &nbsp;Cbb_Name.Items.Add(FieldByName('name').AsString);<br>&nbsp; &nbsp; &nbsp;Next;<br>&nbsp; &nbsp;end;<br>end;
 
with quer1 do<br>&nbsp;begin<br>&nbsp; &nbsp;close;<br>&nbsp; &nbsp;SQL.CommaText:='select distinct name from User';//添加distinct~ 防止重复~<br>&nbsp; &nbsp;Open;<br>&nbsp; &nbsp;First;<br>&nbsp; &nbsp;while not eof do <br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;Cbb_Name.Items.Add(FieldByName('name').AsString);<br>&nbsp; &nbsp; &nbsp;Next;<br>&nbsp; &nbsp;end;<br>&nbsp;end;<br><br>用DBCommbobox控件 更简单~
 
with quer1 do<br>&nbsp;begin<br>&nbsp; &nbsp;close;<br>&nbsp; &nbsp;SQL.CommaText:='select distinct name from User';<br>&nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp;Open;<br>&nbsp; &nbsp;except &nbsp; &nbsp; <br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp;if isempty then Exit;<br>&nbsp; &nbsp;Cbb_Name.items.clear;<br>&nbsp; &nbsp;while not eof do <br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp; &nbsp;Cbb_Name.Items.Add(FieldByName('name').AsString);<br>&nbsp; &nbsp; &nbsp;Next;<br>&nbsp; &nbsp;end;<br>&nbsp;end;
 
begin<br>with quer1 do <br>&nbsp; begin<br>&nbsp; &nbsp; close;<br>&nbsp; &nbsp; SQL.Clear;<br>&nbsp; &nbsp; SQL.Add('Select distinct name from user');<br>&nbsp; &nbsp; Open;<br>&nbsp; &nbsp; quer1.First;<br>&nbsp; &nbsp; commbobox.Items.Add(FieldByName('name').AsString);<br>&nbsp; &nbsp; quer1.Next;<br>&nbsp;end;<br>end;
 
[:D] &nbsp;非常感谢。
 

Similar threads

A
回复
0
查看
933
Andreas Hausladen
A
A
回复
0
查看
806
Andreas Hausladen
A
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部