csharp 如何:将报告绑定到MS SQL Server #report #devexpress

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 如何:将报告绑定到MS SQL Server #report #devexpress相关的知识,希望对你有一定的参考价值。

using System;
using System.Windows.Forms;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.UI;
using DevExpress.Xpo;
// ... 

private SqlDataSource BindToData() {
    // Create a data source with the required connection parameters.   
    MsSqlConnectionParameters connectionParameters = new MsSqlConnectionParameters(
        "localhost", "nwind.mdf", "username", "password", MsSqlAuthorizationType.SqlServer);
    SqlDataSource ds = new SqlDataSource(connectionParameters);

    // Create an SQL query to access the Products table. 
    CustomSqlQuery query = new CustomSqlQuery();
    query.Name = "customQuery";
    query.Sql = "SELECT * FROM Products";

    // Add the query to the collection.  
    ds.Queries.Add(query);

    // Make the data source structure displayed   
    // in the Field List of an End-User Report Designer.  
    ds.RebuildResultSchema();

    return ds;
}

private XtraReport CreateReport() {
    // Create a new report instance. 
    XtraReport report = new XtraReport();

    // Assign the data source to the report. 
    report.DataSource = BindToData();
    report.DataMember = "customQuery";

    // Add a detail band to the report. 
    DetailBand detailBand = new DetailBand();
    detailBand.Height = 50;
    report.Bands.Add(detailBand);

    // Add a label to the detail band. 
    XRLabel label = new XRLabel { WidthF = 300 };
    label.DataBindings.Add("Text", null, "customQuery.ProductName");
    detailBand.Controls.Add(label);

    return report;
}

private void button1_Click(object sender, EventArgs e) {
    // Show the report's print preview. 
    ReportPrintTool printTool = new ReportPrintTool(CreateReport());
    printTool.ShowPreview();
}

private void button2_Click(object sender, EventArgs e) {
    // Open the report in an End-User Designer. 
    ReportDesignTool designTool = new ReportDesignTool(CreateReport());
    designTool.ShowRibbonDesignerDialog();
}

以上是关于csharp 如何:将报告绑定到MS SQL Server #report #devexpress的主要内容,如果未能解决你的问题,请参考以下文章

将 MS Access 报告转换为 SQL Server 报告

如何定期将 MS Access 数据加载到 Azure SQL 中?

更新查询的 MS Access SQL 错误

将 s-s-rS 报告迁移到 AZURE VM,而不迁移本地 SQL 数据库。可能吗?

如何将 AWS ELB 连接到运行 MS SQL 的 RDS?

使用动态布局在 MS Access 中生成报告