报表查看器X Dapper [英] Report Viewer X Dapper

查看:72
本文介绍了报表查看器X Dapper的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Dapper向 ReportDataSource 提供查询。
但是,即使加载了 IEnumerable 的数据,我的报告还是空的。
当您花费 Datatable 工作时。

I'm feeding a ReportDataSource with a query using Dapper. However, I have an empty report, even with an IEnumerable loaded data. When you spend a Datatable works.

如何使用Dapper传递来自查询的数据 ReportViewer

How do I pass data from a query using Dapper for ReportViewer?

this.reportViewer.LocalReport.DataSources.Clear(); 
DataTable dt = new DataTable(); 

dt = CN.Query(Sql, param);

Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource(dt.TableName, dt); 
this.reportViewer.LocalReport.DataSources.Add(rprtDTSource); 
this.reportViewer.RefreshReport(); –


推荐答案

现在看起来像Dapper 支持数据表...

Looks like Dapper now supports the DataTable...

来自测试

public void ExecuteReader()
{
    var dt = new DataTable();
    dt.Load(connection.ExecuteReader("select 3 as [three], 4 as [four]"));
    dt.Columns.Count.IsEqualTo(2);
    dt.Columns[0].ColumnName.IsEqualTo("three");
    dt.Columns[1].ColumnName.IsEqualTo("four");
    dt.Rows.Count.IsEqualTo(1);
    ((int)dt.Rows[0][0]).IsEqualTo(3);
    ((int)dt.Rows[0][1]).IsEqualTo(4);
}

立即 受支持的正在使用DataTable作为TableValueParameter:

Also now supported is using a DataTable as a TableValueParameter:

public void DataTableParameters()
{
    try { connection.Execute("drop proc #DataTableParameters"); } catch { }
    try { connection.Execute("drop table #DataTableParameters"); } catch { }
    try { connection.Execute("drop type MyTVPType"); } catch { }
    connection.Execute("create type MyTVPType as table (id int)");
    connection.Execute("create proc #DataTableParameters @ids MyTVPType readonly as select count(1) from @ids");

    var table = new DataTable { Columns = { { "id", typeof(int) } }, Rows = { { 1 }, { 2 }, { 3 } } };

    int count = connection.Query<int>("#DataTableParameters", new { ids = table.AsTableValuedParameter() }, commandType: CommandType.StoredProcedure).First();
    count.IsEqualTo(3);

    count = connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter("MyTVPType") }).First();
    count.IsEqualTo(3);

    try
    {
        connection.Query<int>("select count(1) from @ids", new { ids = table.AsTableValuedParameter() }).First();
        throw new InvalidOperationException();
    } catch (Exception ex)
    {
        ex.Message.Equals("The table type parameter 'ids' must have a valid type name.");
    }
}

这篇关于报表查看器X Dapper的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆