[MS Access] Alle Tabellennamen auslesen

d-Stench

Erfahrenes Mitglied
Hallo!

kann mir jamand ein Beispiel schreiben, wie ich die vorhandenen Tabellen (nur Namen) in der DB auslesen kann

Danke
 
Hallo!

ich denke, dass geht nur per VB(A):
Code:
 Dim cat As New ADOX.Catalog
 Set cat.ActiveConnection = CurrentProject.Connection
 For Each tbl In cat.Tables
 	Debug.Print tbl.Name
 Next tbl
 Set cat = Nothing

Verweis:
Microsoft ADO Ext. 2.7 for DDL and Security hinzufügen.

Gruß Tom

Gruß Tom
 
Hallo!

Na klar:
Code:
  using System;
  using System.Data;
  using System.Data.OleDb;
  
  namespace DatabaseSchemaExplorerExample
  {
  	/// <summary>
  	/// Zusammendfassende Beschreibung für DatabaseSchemaExplorer
  	/// </summary>
  	class DatabaseSchemaExplorer
  	{
  		/// <summary>
  		/// Der Haupteinstiegspunkt für die Anwendung.
  		/// </summary>
  		[STAThread]
  		static void Main(string[] args)
  		{
  			OleDbConnection oleDbConnection = null;
  			try
  			{
			    oleDbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/Programme/Microsoft Office/Office/Samples/Nordwind.mdb;User Id=;Password=;");
  				oleDbConnection.Open();
			    DataTable dbSchemaTable = oleDbConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[]{null,null,null,"TABLE"});
			    foreach (DataRow row in dbSchemaTable.Rows)
  				{
			    			    Console.WriteLine(row["TABLE_NAME"]);
  				}
  			}
  			finally
  			{
				if(oleDbConnection != null)
  				{
			    			    oleDbConnection.Close();
  				}
  			}
  		}
  	}
  }

Gruß tom
 
Du kannst aber auch in die Tabelle systables (oder so ähnlich) gucken. Da stehen auch alle Tabellennamen drin...
 
Hallo!

ich denke nicht, dass man da über eine "normale Abfrage" -> Abfrageassistent da heran kommt. Was auf jeden Fall geht ist die Abfrage des Datenbank-Katalogs per VBA.

Gruß Tom
 
Kann man diesen Abschnitt:

Code:
foreach (DataRow row in dbSchemaTable.Rows)
  	{
		Console.WriteLine(row["TABLE_NAME"]);
  	}

mit einer WHILE-Schleife realisieren?
 
Zurück