在窗体显示时加载TComboBox中的内容(从某一表中读取),
我做了一个过程,想对所有类似的TComboBox通过参数传递调用此过程。
现我把代码显示如下:(错误提示说from附近有语法错误,请高手给予提示)procedure Tfrmfile.GetFromTableToCombox(fieldname,tablename:string;comboxname:tcombobox);
var
AdoQry:TadoQuery;
StrTableName:string;
StrFieldName:string;
tmpComboxName:Tcombobox;
begin
fieldname:=strfieldname;
tablename:=strfieldname;
tmpcomboxname:=tcombobox.Create(self);
comboxname:=tmpcomboxname;
adoqry:=tadoquery.Create(self);
AdoQry.connection:=datam.ADOConn;
with adoqry do
begin
close;
sql.Add('select ' + fieldname + ' from ' + tablename);
Active:=true;
open;
if recordcount>0 then
begin
first;
while not eof do
begin
comboxname.Items.Add(fieldbyname(fieldname).AsString);
next;
end;
end;
end;
end;
我做了一个过程,想对所有类似的TComboBox通过参数传递调用此过程。
现我把代码显示如下:(错误提示说from附近有语法错误,请高手给予提示)procedure Tfrmfile.GetFromTableToCombox(fieldname,tablename:string;comboxname:tcombobox);
var
AdoQry:TadoQuery;
StrTableName:string;
StrFieldName:string;
tmpComboxName:Tcombobox;
begin
fieldname:=strfieldname;
tablename:=strfieldname;
tmpcomboxname:=tcombobox.Create(self);
comboxname:=tmpcomboxname;
adoqry:=tadoquery.Create(self);
AdoQry.connection:=datam.ADOConn;
with adoqry do
begin
close;
sql.Add('select ' + fieldname + ' from ' + tablename);
Active:=true;
open;
if recordcount>0 then
begin
first;
while not eof do
begin
comboxname.Items.Add(fieldbyname(fieldname).AsString);
next;
end;
end;
end;
end;
解决方案 »
- post如何实现登陆
- 有关gina替换的高难度问题(希望高手来讨论讨论)
- 高手看过来,有散!
- QuickReport 为何只能打印一行数据?且不打印columnband
- 美国开打了,战斧巡航导弹先开路
- 咳咳!过年了,大家把还没有揭的帖子揭一下了!不要拖到下一年,这样不好!
- 请教,在delphi为何提示“多步操作产生错误,请检查每一步状态值”
- 小问题,怎样调出Notepad显示一个文本文件?(前10个有分)
- 推荐个稳定成熟的 浏览 pdf 文档的 ocx 或者组件
- 新人求助 listview遍历窗口进程问题
- 求助高手Delphi Bpl 包的调用问题?
- 本人用Delphi写了个程序,想用B5的纸打印,但是打印出来的还是A4的样式,请问这是为什么??
'select ' + fieldname + ' from ' + tablename
showmessage出来看看
fieldname与tablename是否正确
begin
//cmb.Clear;
cmb.clear;
socketread.Open;
cds.Data := socketRead.appserver.TT_S006002(ssql);
cds.First; while not cds.Eof do
begin
cmb.Items.add(cds.fields[0].asstring);
cds.Next;
end; socketRead.close;end;
自己看看,应该可以给一些帮助
cmbFIll(CdsCmb, sgroup, Cmbgroup);
procedure GetComboList(Combo: TComboBox; str: string;
strtablename: string; AdditionStr: string = '');
var
i: Integer;
dsTemp: TADODataSet;
begin
dsTemp := TADODataSet.Create(Application);
dsTemp.Connection := FrmShebeiMain.ADOConnection1;
dsTemp.CommandText := 'select distinct ' + str + ' from ' + strtablename +
' where ' + str + '<>' + ''' ''' + AdditionStr;
dsTemp.filtered := false;
dsTemp.Active := True;
Combo.Items.Clear;
combo.text := '';
if dsTemp.RecordCount > 0 then
begin
dsTemp.First;
Combo.Items.Add('');
for i := 0 to dsTemp.RecordCount - 1 do
begin
Combo.Items.Add(Trim(dsTemp.FieldByName(str).AsString));
dsTemp.Next;
end;
end;
dsTemp.Free;
end;
ADOConnection:TADOConnection;Strings: TStrings);
-----------
procedure TForm1.GetFromTableToCombox(FieldName,TableName:string;ADOConnection:TADOConnection;
Strings:TStrings);
var
AdoQry:TadoQuery;
begin
adoqry:=tadoquery.Create(self);
AdoQry.connection:=ADOConnection; Assert((trim(FieldName)<>'') and (trim(TableName)<>''),'SQL 语句错误'); with adoqry do
begin
sql.Add('select ' + FieldName + ' from ' + TableName);
open; if RecordCount>0 then
begin
first;
while not Eof do
begin
Strings.Add(FieldByName(FieldName).AsString);
next;
end;
end;
close;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
GetFromTableToCombox('sup_id','supp',ADOConnection1,ComboBox1.Items)
end;