从 C# 代码访问报告

Reaching access Reports from C# code

我已经在 Microsoft Access 数据库中创建了一份报告

现在我想在我的项目中使用它,但我无法在网上找到任何东西

我想做的是

用数据填充报告并打印它而不在屏幕上显示任何内容

How to automate Microsoft Access by using Visual C# MS 支持站点上的文章介绍了如何使用 C# 自动执行访问操作。

有关您的问题,请参阅打印或预览访问报告部分。

To preview or to print an Access report, you call the OpenReport method of the DoCmd object. When you call OpenReport, one of the arguments that you pass determines whether the report is previewed on the screen, or whether it is sent to the printer:

// Preview a report named Sales:
oAccess.DoCmd.OpenReport(
    "Sales", //ReportName
    Access.AcView.acViewPreview, //View
    System.Reflection.Missing.Value, //FilterName
    System.Reflection.Missing.Value //WhereCondition
);

根据 MS 文档,使用第 4 个参数你应该能够传递一个 :

A string expression that's a valid SQL WHERE clause without the word WHERE

例如,如果要显示记录 ID 292 的报告,只需将 System.Reflection.Missing.Value //WhereCondition 替换为 "ID=292"

据我所知,无法直接从 C# 代码填充报告字段。