【问题标题】:How to open an Access form, from within a Visual Studio C# Winform?如何从 Visual Studio C# Winform 中打开 Access 表单?
【发布时间】:2011-12-22 17:12:41
【问题描述】:

我的 Visual Studio 2010 Windows 表单 (c#) 中需要一个链接(很可能是按钮或类似的),这将打开一个预先开发的访问表单。这很棘手还是比听起来更简单=P

问候,Bserk

【问题讨论】:

    标签: c# winforms visual-studio-2010 ms-access


    【解决方案1】:

    说明

    假设您指的是 Microsoft Access 数据库,您可以使用 System.Diagnostics.Process 打开任何文件/程序。

    示例

    Process.Start("PathAndFileNameOfYourAccessDb");
    

    更多信息

    【讨论】:

      【解决方案2】:

      您可以使用 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;
              }
          }
      }
      

      【讨论】:

        【解决方案3】:

        执行此操作的最简单方法是使用 /x 命令行开关。这将启动一个在命令行上命名的宏。

        • 在您的数据库中创建一个新宏,
        • 下拉列表并选择 OpenForm,
        • 输入预定义表单的名称
        • 设置您需要的选项。
        • 保存宏并为其命名,例如 MyMacro

        然后使用数据库名称和 /x 开关执行 MSAccess,如下所示:

        "c:\Program Files\Microsoft Office\Office14\MSACCESS.EXE" "C:\Users\user\Documents\Database1.accdb" /x MyMacro
        

        访问将打开具有命名表单的数据库。

        【讨论】:

          猜你喜欢
          • 2021-10-04
          • 1970-01-01
          • 2020-04-25
          • 2010-11-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多