【发布时间】:2011-12-22 17:12:41
【问题描述】:
我的 Visual Studio 2010 Windows 表单 (c#) 中需要一个链接(很可能是按钮或类似的),这将打开一个预先开发的访问表单。这很棘手还是比听起来更简单=P
问候,Bserk
【问题讨论】:
标签: c# winforms visual-studio-2010 ms-access
我的 Visual Studio 2010 Windows 表单 (c#) 中需要一个链接(很可能是按钮或类似的),这将打开一个预先开发的访问表单。这很棘手还是比听起来更简单=P
问候,Bserk
【问题讨论】:
标签: c# winforms visual-studio-2010 ms-access
假设您指的是 Microsoft Access 数据库,您可以使用 System.Diagnostics.Process 打开任何文件/程序。
Process.Start("PathAndFileNameOfYourAccessDb");
【讨论】:
您可以使用 CodePlex 上的 Library NDde 通过 DDE 与 Access 应用程序进行通信。
这是从我的一个项目中提取的代码片段:
using (DdeClient client = new DdeClient("MSAccess", Path.GetFileName(theAccessApp))) {
if (!TryConnect(client)) {
Process.Start(theAccessApp);
Thread.Sleep(2000);
if (!TryConnect(client)) {
Messagebox.Show("Could not start: " + theAccessApp);
return;
}
}
// Close the form if open
client.Execute("[Close 2, \"MyForm\"]", 10000);
// Open the form
string openCmd = String.Format("[OpenForm \"MyForm\",,,,,,\"{0}\"]", anyOpenArgsParam);
client.Execute(openCmd, 10000);
}
有
private static bool TryConnect(DdeClient client)
{
try {
client.Connect();
return true;
} catch (DdeException) {
try {
client.Connect();
return true;
} catch (DdeException) {
return false;
}
}
}
【讨论】:
执行此操作的最简单方法是使用 /x 命令行开关。这将启动一个在命令行上命名的宏。
然后使用数据库名称和 /x 开关执行 MSAccess,如下所示:
"c:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" "C:\Users\user\Documents\Database1.accdb" /x MyMacro
访问将打开具有命名表单的数据库。
【讨论】: