gpt4 book ai didi

c# - 如何加载数据表作为 ReportDataSource?

转载 作者:太空狗 更新时间:2023-10-30 00:02:12 24 4
gpt4 key购买 nike

我正在尝试做类似的事情:

this.reportViewer.LocalReport.DataSources.Clear();
DataTable dt = new DataTable();
dt = this.inputValuesTableAdapter.GetData();
Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource();

rprtDTSource = dt; // this line generates exception

//this.reportViewer.LocalReport.DataSources.Add(rprtDTSource);
this.reportViewer.RefreshReport();

如何加载数据表作为 ReportDataSource?

当前代码产生:“无法将类型‘System.Data.DataTable’隐式转换为‘Microsoft.Reporting.WinForms.ReportDataSource’”

最佳答案

您没有正确初始化 ReportDataSouce。试一试:

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

Microsoft.Reporting.WinForms.ReportDataSource rprtDTSource = new Microsoft.Reporting.WinForms.ReportDataSource(dt.TableName, dt);

this.reportViewer.LocalReport.DataSources.Add(rprtDTSource);
this.reportViewer.RefreshReport();

此外,您可能需要更改 ReportDataSource 构造函数的第一个参数,以设置您的报表所期望的数据源的名称。

关于c# - 如何加载数据表作为 ReportDataSource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4004307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com