0
我正在C#中執行一個連接到Access數據庫的ASP.NET應用程序,現在我希望它將報告導出爲PDF。這裏是我的代碼,只連接到Access,我想運行一個訪問宏或與Microsoft.Office.Interop.Access.Application DoCmd.OutputTo運行命令,但我不知道如何使用它。任何幫助?以PDF格式導出訪問報告
string user = "myUser";
string pass = "myPass";
string host = "myHost";
OleDbConnection connection = new OleDbConnection(@"Provider = Microsoft.ACE.OLEDB.12.0; Data Source = myPath");
string _command = ...; //I don't know what put here
try
{
OleDbCommand command = new OleDbCommand(_command, connection);
command.CommandText = ...; //I don't know what put here
int temp = command.ExecuteNonQuery();
Console.WriteLine("PDF created!");
}
你在這裏錯了路。您可以將報表打印爲PDF,但由於連接到Access數據庫(處理表,查詢和數據宏的報表,而不是報表,表單,VBA和普通宏)而不是應用程序,因此無法使用OleDb訪問報表。這:https://support.microsoft.com/en-us/help/317114/how-to-automate-microsoft-access-by-using-visual-c是使用COM和使用Access應用程序的一個很好的入門者,而不是數據庫。但是試着先打印到在Access中工作的PDF,然後嘗試在C#中實現它。 –
你爲什麼不使用RDLC報告?它提供內置功能,可以將報告導出爲PDF或其他格式,無需預覽給用戶。 –
謝謝,我會搜索自動訪問,但我不知道什麼是RDLC報告,我不知道如何使用Access。 –