熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> SQL Server >> 正文

測試使用 ADOX方 便的查詢表和字段

2022-06-13   來源: SQL Server 

  
  添加個列表框個按鈕
  
  引用微軟 ADO ExtX for dll and Security
  
  Dim cat As ADOXCatalog
  
  Dim cnn As ADODBConnection
  
  Dim tbl As ADOXTable
  
  Private Sub Command_Click()
  
  On Error Resume Next
  
  For Each tbl In catTables
  
  如果是sqlserver數據庫則變成If Left(tblName ) <> sys
  
  If Left(tblName ) <> MSys Then
  
  ListAddItem tblName
  
  End If
  
  Next
  
  End Sub
  
  Private Sub Form_Load()
  
  Set cnn = New ADODBConnection
  
  Set cat = New ADOXCatalog
  
  cnnOpen Provider=MicrosoftJetOLEDB;Data Source=F:\csdn_vb\database\articlemdb
  
  cnnOpen Provider=SQLOLEDB;Persist Security Info=False;User ID=sa;Initial Catalog=northwind;Data Source=yang
  
  Set catActiveConnection = cnn
  
  End Sub
  
  Private Sub Form_Unload(Cancel As Integer)
  
  Set cat = Nothing
  
  Set con = Nothing
  
  End Sub
  
  Private Sub List_Click()
  
  Dim fld
  
  Dim intfield As Integer
  
  ListClear
  
  intfield = catTables(ListList(ListListIndex))ColumnsCount
  
  For i = To intfield
  
  Set fld = catTables(ListList(ListListIndex))Columns(i)
  
  ListAddItem fldName & & fldType & & fldDefinedSize
  
  Next
  
  End Sub
  

From:http://tw.wingwit.com/Article/program/SQLServer/201311/22061.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.