简体   繁体   English

当Access mdb具有密码时,来自C#的MailMerge

[英]MailMerge from C# when Access mdb has password

I am trying to use MailMerge programatically ( from C# ). 我正在尝试以编程方式使用MailMerge(来自C#)。 I am using an Access database file as a data source. 我正在使用Access数据库文件作为数据源。 The Access database has a password. Access数据库具有密码。 The following code does not work for some reason even though it should. 即使出于某些原因,以下代码也不起作用。 I get an invalid password textbox. 我收到无效的密码文本框。

       WordApp = new ApplicationClass();

        WordApp.Visible = true;

        adoc = WordApp.Documents.Open(ref Template,
                             ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
                             ref Missing, ref Missing, ref Missing, ref Missing, ref Missing,
                             ref Missing, ref Missing, ref Missing, ref Missing, ref Missing);


        Object sql = "SELECT * FROM TestMergeTest";

        Object conn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + @"C:\Documents and Settings\sebastianharko.AKA-OS\Desktop\See.mdb" + ";"
             + "Jet OLDEDB:Database Password=" + @"notpassword" + ";";

        Object password = "notpassword";

        adoc.MailMerge.OpenDataSource(@"C:\Documents and Settings\sebastianharko.AKA-OS\Desktop\See.mdb", ref Missing,
              ref Missing, ref Missing, ref Missing, ref Missing,
             ref Missing, ref Missing, ref Missing, ref Missing,ref Missing, ref conn, ref sql, ref Missing, ref Missing, ref Missing);

Any help would be greatly appreciated. 任何帮助将不胜感激。

Are you sure about the formatting of the connection string? 您确定连接字符串的格式吗? Here's an example I got by Googling 'Jet 4.0 connection string:" 这是我通过Google搜索'Jet 4.0连接字符串得到的示例:“

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=zzyzz;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM