我正在尝试从vb.net 2010中的ms access 2010运行宏..
我使用的代码是
Dim oAccess As Access.ApplicationClass
'Start Access and open the database.
oAccess = CreateObject("Access.Application")
oAccess.Visible = True
oAccess.OpenCurrentDatabase("C:\Users\Yuganshu\Desktop\New folder (4)\WindowsApplication1\db.mdb", False)
'Run the macros.
oAccess.Run("Macro1")
'oAccess.Run("DoKbTestWithParameter", "Hello from VB .NET Client")
'Clean-up: Quit Access without saving changes to the database.
oAccess.DoCmd().Quit(Access.AcQuitOption.acQuitSaveNone)
System.Runtime.InteropServices.Marshal.ReleaseComObject(oAccess)
oAccess = Nothing
这给了我以下错误:
无法将类型为“Microsoft.Office.Interop.Access.ApplicationClass”的COM对象强制转换为类类型“WindowsApplication1.Access.ApplicationClass”。表示COM组件的类型实例不能转换为不代表COM组件的类型;但是只要底层的COM组件支持对接口的IID的QueryInterface调用,它们就可以转换为接口。
我不知道该怎么做。
答案 0 :(得分:1)
您需要添加正确的COM参考。单击项目菜单栏,然后单击 - >添加引用。在“类型库”下,查找Microsoft Access 14.0或您的计算机正在运行的任何版本。然后添加以下语句。
SELECT *
FROM (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY updateDate DESC) rn
FROM a
GROUP BY
id
) ag
JOIN (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY id ORDER BY updateDate DESC) rn
FROM b
GROUP BY
id
) bg
ON bg.id = ag.id
WHERE ag.rn = 1
AND bg.rn = 1