用adoconnection的gettablenames
如adoconnection1gettablenames(listbox1items);
就把数据库中的所有表名写到listbox1中,之后你再进行判断就可以啦
您好,procedure TForm1Button1Click(Sender: TObject);
var
sql,str,tbl:string;
NodeD,NodeT: TTreeNode;
begin
sql:='select name from mastersysdatabases order by name';
ADOQ1Close;
ADOQ1SQLClear;
ADOQ1SQLAdd(sql);
ADOQ1Open;
while not ADOQ1Eof do
begin
NodeD:=TreeviewItemsAdd(nil,ADOQ1FieldByName('name')AsString);
NodeT:=NodeD;
str:=ADOQ1FieldByName('name')AsString;
tbl:='';
sql:='select Aname TBL,Bname FLD from '+str+'sysobjects A,'+str+'syscolumns B where Aid=Bid AND Axtype=''U'' order by AName,BColorder';
ADOQ2Close;
ADOQ2SQLClear;
ADOQ2SQLAdd(sql);
ADOQ2Open;
while not ADOQ2Eof do
begin
if ADOQ2FieldByName('TBL')AsString=tbl then
begin
TreeViewItemsAddChild(NodeT,ADOQ2FieldByName('FLD')AsString);
end
else
begin
tbl:=ADOQ2FieldByName('TBL')AsString;
NodeT:=TreeViewItemsAddChild(NodeD,tbl);
TreeViewItemsAddChild(NodeT,ADOQ2FieldByName('FLD')AsString);
end;
ADOQ2Next;
end;
ADOQ1Next;
end;
end;
在form上放两个ADOQuery: ADOQ1,ADOQ2,链接好数据库,再放一个按钮,以上是个按钮事件,已经调试通过了,没有问题。
怎样使用一个查询获得数据库对象的名称(查询/窗体/表/报表/模块/宏)
方法一:
请详细参阅ADO参考文档中OpenSchema
如:
'功能:获取access库中表的个数及表的名称
'用ado怎样实现
'工程--->引用--->Microsoft ActiveX Data Object 2x(版本号)
'----------------------------------------------------------------------------
Private Sub Form_Load()
Dim adoCN As New ADODBConnection '定义数据库的连接
Dim strCnn As New ADODBRecordset
Dim rstSchema As New ADODBRecordset
Dim I As Integer
str1 = "Provider=MicrosoftJetOLEDB40;Data Source=c:\NorthwindMDB;Persist Security Info=False"
adoCNOpen str1
Set rstSchema = adoCNOpenSchema(adSchemaTables)
Do Until rstSchemaEOF
If rstSchema!TABLE_TYPE = "TABLE" Then
out = out & "Table name: " & _
rstSchema!TABLE_NAME & vbCr & _
"Table type: " & rstSchema!TABLE_TYPE & vbCr
I = I + 1
End If
rstSchemaMoveNext
Loop
MsgBox I
rstSchemaClose
adoCNClose
DebugPrint out
End Sub
方法二:
Access 系统表 MsysObjects 包含了数据库对象列表, 尽管未在文档中记载, 你仍可通过查询它来获取你想要的
注: 请不要有意或无意地修改任何ACCESS系统表,否则会出现不可意料的情况
使用下列 SQL 语句来获取你想要的
查询:
SELECT MSysObjectsName FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjectsType)=5 ORDER BY MSysObjectsName;
窗体:
SELECT MSysObjectsName FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjectsType)=-32768 ORDER BY MSysObjectsName;
表:
SELECT MSysObjectsName FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (Left$([Name],4) <> "Msys") AND (MSysObjectsType)=1 ORDER BY MSysObjectsName;
报表:
SELECT MSysObjectsName FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjectsType)= -32764 ORDER BY MSysObjectsName;
模块:
SELECT MSysObjectsName FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjectsType)= -32761 ORDER BY MSysObjectsName;
宏:
SELECT MSysObjectsName FROM MsysObjects WHERE (Left([Name],1)<>"~") AND (MSysObjectsType)= -32766 ORDER BY MSysObjectsName;
以上就是关于Delphi SQl查询access数据表名全部的内容,包括:Delphi SQl查询access数据表名、怎么把本机上的所有数据库名及其下的各表名显示到treeview中、如何获取ACCESS中有多少个用户表,以及表名称。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)