获得表名:
Session.GetTableNames
MyStringList := TStringList.Create;
try
Session.GetTableNames('YourSQLAlias', '',False, False, MyStringList);
{ Add the table names to a list box }
ListBox1.Items = MyStringList;
finally
MyStringList.Free;
end;获得字段名,需要打开这个表,比如:
Query1.Close;
Query1.SQL.Text := Format('select * from %s where 1=0', [ListBox1.Items[0]]);
Query1.Open;
for i := 0 to Query1.FieldCount - 1 do
ListBox2.Items.Add(Query1.Fields[i].FieldName);
Session.GetTableNames
MyStringList := TStringList.Create;
try
Session.GetTableNames('YourSQLAlias', '',False, False, MyStringList);
{ Add the table names to a list box }
ListBox1.Items = MyStringList;
finally
MyStringList.Free;
end;获得字段名,需要打开这个表,比如:
Query1.Close;
Query1.SQL.Text := Format('select * from %s where 1=0', [ListBox1.Items[0]]);
Query1.Open;
for i := 0 to Query1.FieldCount - 1 do
ListBox2.Items.Add(Query1.Fields[i].FieldName);
Select * from TableName
这是SQL Server中的存储过程
在Delphi中可以用数据集.FieldCount,就可以得到相应表的字段个数
FieldNameStrList: TStringList;
FieldNameStringList := TStringList.Create;
try
for i := 0 to MyStringList.Count - 1 do
begin
FieldNameStrList.Add(Format('Table%d: %s', [i, MyStringList.strings[i]);
ADOConnection.GetFieldNames(MyStringList.Strings[i], FieldNameStrList);
......
end;
finally
FieldNameStrList.Free;
MyStringList.Free;
end;
when (OBJECTPROPERTY(o.id, N'IsMSShipped')=1) then 1
else OBJECTPROPERTY(o.id, N'IsSystemTable') end)
into #Temp1
from dbo.sysobjects o, dbo.sysindexes i
where OBJECTPROPERTY(o.id, N'IsTable') = 1 and i.id = o.id
and i.indid < 2 and o.name not like N'#%' order by TableName
select TableName from #Temp1 where SystemObj=0
@TableName varchar(254)
As
select c.name,c.ColID,Type=d.Name,Length=c.Length,Prec=c.xPrec,Scale=c.xScale,c.colid
from syscolumns c,dbo.systypes d
where id=object_id(@TableName) and c.xusertype=d.xusertype
里面有详细例子,一定可以用的