Verknüpfte Tabellen in Access mittels C# und ADO.NET erstellen/manipulieren



  • Hi,

    der Titel sagt es eigentlich schon. Ich müsste mit ADO.NET und C# verknüpfte Tabellen in MS Access (2003) anlegen und die bei Bedarf auch auf eine andere Datenbank umbiegen können (d.h. die Verknüpfung ändern).
    Google hat leider nur etwas mit DAO und VB(6) zu Tage gefördert, was hier nicht wirklich hilfreich ist. Auch würde ich gerne um ADOX rumkommen und bevorzugt ADO.NET für diesen Weg einsetzen.

    Für einen Schubs in die richtige Richtung oder andersweitige Hilfe wäre ich dankbar 🙂

    Cheers

    GPC



  • Hab's jetzt doch mit ADOX gemacht, was zwar nicht überragend ist, aber zumindest funktioniert.

    public static void CreateLinkedTable(OleDbConnection sourceDb, OleDbConnection targetDb, string linkName, string targetTable) {
        DODB.ConnectionClass connection = null;
        try {
    		//Open a ADODB connection
    		connection = new ADODB.ConnectionClass();
    		connection.Open(sourceDb.ConnectionString, "", "", 0);
    
    		//Create the ADOX catalog with the newly opened connection
    		ADOX.CatalogClass catalog = new ADOX.CatalogClass();
    		catalog.ActiveConnection = connection;
    
    		//Create a ADOX table
    		ADOX.TableClass table = new ADOX.TableClass();
    		table.ParentCatalog = catalog;
    		table.Name = linkName;
    
    		//Set properties of the new table
    		table.Properties["Jet OLEDB:Remote Table Name"].Value = targetTable;
    		table.Properties["Jet OLEDB:Link Datasource"].Value = targetDb.DataSource;
    		table.Properties["Jet OLEDB:Link Provider String"].Value = "MS Access";
    		table.Properties["Jet OLEDB:Create Link"].Value = true;
    
    		catalog.Tables.Append(table);
    	}
    	catch (Exception ex) {
    		throw ex;
    	}
    	finally {
    		connection.Close();
    	}
    }
    


  • Hi, wieso handelst du das ganze nicht einfach mit ConnectionsStrings und DataAdaptern?



  • NozzNazz schrieb:

    Hi, wieso handelst du das ganze nicht einfach mit ConnectionsStrings und DataAdaptern?

    Inwiefern helfen mir DataAdapter bei dieser Problemstellung?


Anmelden zum Antworten