从数据库中查询出ComboBox1下拉列表中的值

gazhangting 2005-12-07 05:37:45
我们通常的哪个下拉列表,要下很多,通常用户在使用中也不方便,如果能从数据库中查询出来的话,我们每使用的时候,只要在数据库中添加就是了,如果不要了,可以删了,不知哪个大哥用过使个方法,本人的例子如下:是错了的.

ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('select classname from class where classname=:ClassID');
ADOQuery2.parameters.ParamByName('ClassID').value:=ComboBox1.Items[ComboBox1.ItemIndex];
ADOQuery2.Open;
if ADOQuery2.RecordCount<>0 then
mboBox1:=ADOQuery2.FieldByName('class').value;
...全文
117 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
samcrm 2005-12-08
  • 打赏
  • 举报
回复
ADOQuery2.Parameters.ParamValues['Report_id']:=ComboBox1.Text;
应为
ADOQuery2.Parameters.ParamValues[ClassID']:=ComboBox1.Text;
qizhanfeng 2005-12-08
  • 打赏
  • 举报
回复
deansroom(丁樵方玉)的就行了
对于楼上的ADOQuery2.Parameters.ParamValues['Report_id']:=ComboBox1.Text; 本人不懂 虚心求教
给参数赋值
deansroom 2005-12-07
  • 打赏
  • 举报
回复
本人刚入门 自己总结的方法如下
mboBox1.Items.Clear;
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('select classname from class');
ADOQuery2.Open;
first;
while not ADOQuery2.Eof do
begin
mboBox1.Items.add(ADOQuery2.fieldvalue['classname']);
//括号中也可以是adoquery2.fieldbyname('classname').asstring;
ADOQuery2.Next;
end;

对于楼上的ADOQuery2.Parameters.ParamValues['Report_id']:=ComboBox1.Text; 本人不懂 虚心求教
samcrm 2005-12-07
  • 打赏
  • 举报
回复
mboBox1.Items.Clear;
ADOQuery2.Close;
ADOQuery2.SQL.Clear;
ADOQuery2.SQL.Add('select classname from class where classname=:ClassID');
ADOQuery2.Parameters.ParamValues['Report_id']:=ComboBox1.Text;
ADOQuery2.Open;
while not ADOQuery2.Eof do
begin
mboBox1.Items.Append(ADOQuery2['classname']);
ADOQuery2.Next;
end;

2,496

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧