Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Perhaps this code from <a href="http://cookingwithcsharp.blogspot.com/2007/11/how-to-quickly-copy-tables-from-odbc.html" rel="nofollow noreferrer">How to quickly copy tables from an ODBC source to MS Access within a C# project</a> might help:</p> <blockquote> <p>The VB function you’ll need to put into MS Access is quite simple, and basically calls the TransferDatabase method by passing it a DSN (pointing to the source database), a source table name and target table name. The code is as follows:</p> </blockquote> <pre><code>Public Function Import(dsnName As String, sourceTableName As String, targetTableName As String) ‘ if the table already existsm, delete it. On Error GoTo CopyTable DoCmd.DeleteObject acTable, targetTableName CopyTable: DoCmd.TransferDatabase _ acImport, _ "ODBC Database", _ "ODBC;DSN=" + dsnName, _ acTable, _ sourceTableName, _ targetTableName End Function </code></pre> <blockquote> <p>And then the C# code:</p> </blockquote> <pre><code>object accessObject = null; try { accessObject = Activator.CreateInstance(Type.GetTypeFromProgID("Access.Application")); accessObject.GetType().InvokeMember( "OpenCurrentDatabase", System.Reflection.BindingFlags.Default System.Reflection.BindingFlags.InvokeMethod, null, accessObject, new Object[] { "AccessDbase.mdb" }); accessObject.GetType().InvokeMember( "Run", System.Reflection.BindingFlags.Default System.Reflection.BindingFlags.InvokeMethod, null, accessObject, new Object[] { "Import", "DSN Name", "Source table name", "Target table name" }); accessObject.GetType().InvokeMember( "CloseCurrentDatabase", System.Reflection.BindingFlags.Default System.Reflection.BindingFlags.InvokeMethod, null, accessObject, null); MessageBox.Show("Copy succeeded."); } catch (Exception ex) { string message = ex.Message; while (ex.InnerException != null) { ex = ex.InnerException; message += "\r\n----\r\n" + ex.Message; } MessageBox.Show(message); } finally { if (accessObject != null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(accessObject); accessObject = null; } } </code></pre> <p>Changing the VBA to read acLink rather than acImport should allow linking.</p> <p><strong>Edit re comments</strong></p> <p>I cannot help with c#, but here is some VBScript that links a table from one MDB to another.</p> <pre><code>strLinkFile = "C:\Docs\Link.mdb" strAccessFile = "C:\Docs\LTD.mdb" 'Create Link... ' Set cn = CreateObject("ADODB.Connection") cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &amp; _ "Data Source=" &amp; strAccessFile &amp; ";" &amp; _ "Persist Security Info=False" Set adoCat = CreateObject("ADOX.Catalog") Set adoCat.ActiveConnection = cn Set adoTbl = CreateObject("ADOX.Table") Set adoTbl.ParentCatalog = adoCat adoTbl.Name = "LinkTable" adoTbl.properties("Jet OLEDB:Link Datasource") = strLinkFile adoTbl.properties("Jet OLEDB:Link Provider String") = "MS Access" adoTbl.properties("Jet OLEDB:Remote Table Name") = "Table1" adoTbl.properties("Jet OLEDB:Create Link") = True 'Append the table to the tables collection ' adoCat.Tables.Append adoTbl </code></pre> <p>It is modified from: <a href="http://support.microsoft.com/kb/240222" rel="nofollow noreferrer">http://support.microsoft.com/kb/240222</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload