var tables : TStringList; begintables := TStringList.Create; conn1.GetTableNames(tables); for i:= 0 to tables.count do with TLabel.Create(Self ) do begin Parent:= Self; Left := 30; top := 20 + i * 30; Caption := Tables.Strings[i];end; end;
首先连接你的数据库; 在查询表名,用"select table_name from Tables"这句SQL具体要根据你的数据库来,你可以参考你所用的数据库的数据字典; 再循环创建label并赋值
KAO,会搞数据库就算是老大吗,那不是太多了
很难吗? var query:TADOQuery; i:integer; begin query:=tadoquery.Create(self); query.Connection:=ADOConnection1; try with query do begin close; sql.clear; sql.Add('sp_tables'); open; first; i:=0; while not eof do begin with TLabel.Create(Self ) do begin Parent:= Self; Left := 30; top := 20 +i* 30; Caption := query.Fieldbyname('table_name').AsString; i:=i+1; end; next; end; end; except showmessage('Êý¾Ý¿âÁ¬½Óʧ°Ü!'); exit; end;end;
tables : TStringList;
begintables := TStringList.Create;
conn1.GetTableNames(tables);
for i:= 0 to tables.count do
with TLabel.Create(Self ) do
begin
Parent:= Self;
Left := 30;
top := 20 + i * 30;
Caption := Tables.Strings[i];end;
end;
在查询表名,用"select table_name from Tables"这句SQL具体要根据你的数据库来,你可以参考你所用的数据库的数据字典;
再循环创建label并赋值
var
query:TADOQuery;
i:integer;
begin
query:=tadoquery.Create(self);
query.Connection:=ADOConnection1;
try
with query do
begin
close;
sql.clear;
sql.Add('sp_tables');
open;
first;
i:=0;
while not eof do
begin
with TLabel.Create(Self ) do
begin
Parent:= Self;
Left := 30;
top := 20 +i* 30;
Caption := query.Fieldbyname('table_name').AsString;
i:=i+1;
end; next;
end;
end; except
showmessage('Êý¾Ý¿âÁ¬½Óʧ°Ü!');
exit;
end;end;