如何把数据库里的开头字为ttd的表全部赋到COMBOBOX里?(20分)

  • 主题发起人 主题发起人 guguda
  • 开始时间 开始时间
G

guguda

Unregistered / Unconfirmed
GUEST, unregistred user!
SQL数据库
其中一个库里有数个以TTD开头的表(如ttdss0202),怎么才能把这些以TTD开表头的做一个赋值放到COMBOBOX的列表框里有用户选择?
实际就是有点像选择表,只是加了条件。
请问这个代码要怎么写?
谢谢。
 
select * from table where field like "ttd%"
 
TAdoConnection或TDataBase 有GetTableNames(List: TStrings; SystemTables: Boolean = False) 方法的呀,
将的到的所有表(不含系统表SystemTables:=False)放入List中,然后在对List逐个检查,看是否合以TTD开头,如
果是,则用Combobox.items.add()方法加入就行了.
 
Select name from Sysobjects where Type='U' and name like 'ttd%'

然后把数据赋给Combobox列表
 
同意DEN,你的意思是得到数据库中表名

ADOConnection1.GetTableNames(Combobox.items, False);
 
Select name from Sysobjects where Type in ('U','V') and name like 'ttd%'

然后把数据赋给Combobox列表
这样可以获得所有符合要求的表和视图
 
with ADOQuery4 do
begin
Close;
SQL.Clear;
SQL.Add ('select * from sysobjects');
SQL.Add ('where type = ('U','V') and name like ''sourcedetail%''); //为什么这句里的U会出错?
Open;
First;
while Not Eof do
begin
ComboBox1.Items.Add (); //括号里应怎么写?
Next;
end;
end;
 
SQL.Add ('where type = (''U'',''V'') and name like '''+sourcedetail+'%''');

看来你什么都不懂
 
lhzzj你的语法怎么有问题?

我用:
SQL.Add ('where type = (''U'',''V'') and name like ''ttd%''');
combobox1.items.add(adoquery1.fieldbyname('name').value);
运行没有错,但是COMBOBOX里是空的啊。
 
使用
select * from sysobjects where type in ('U','V') and name like 'ttd%'
试了一下,可以找到
看来只是存到COMBOBOX里时有问题。
不知这个问题要怎么解决?
 
谢谢大家,问题解决了。
 
多人接受答案了。
 
后退
顶部