3

Datatableas datasourceinについての最後の質問で検索していましたが、ReportViewerこれが解決策として見つかりました

DataTable table = new DataTable();
table.Columns.Add("value", typeof(string));
table.Columns.Add("price", typeof(string));
table.Columns.Add("quantity", typeof(string));

table.Rows.Add("test1","10","20");
table.Rows.Add("test2", "10", "20");

reportViewer1.LocalReport.DataSources.Clear();

ReportDataSource rprtDTSource = new ReportDataSource("TITLE",table);

reportViewer1.LocalReport.DataSources.Add(rprtDTSource);
reportViewer1.RefreshReport();

しかし、私は結果としてこの画像を取得します

ここに画像の説明を入力

何が問題ですか ??

4

3 に答える 3

5

レポート ビューアー コントロールのレポート ソースを設定するのを忘れているようです。次のいずれかのオプションを使用して、レポート ソースを設定できます。

たとえば、プロジェクトにレポートを追加したとします。レポート ビューアーで次のように表示できます。

var reportDataSource1 = new ReportDataSource("NameOfReportDataSet", YourDataTable);
this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);
this.reportViewer1.LocalReport.ReportEmbeddedResource = "Namespace.ReportName.rdlc";
this.reportViewer1.RefreshReport();

また、デザイナーを使用してレポート ビューアーのレポートを簡単に設定できます。フォームにレポート ビューアーを配置し、右上の矢印をクリックしてレポート ビューアーのスマート タグ ウィンドウを開き、コンボ ボックスからレポートを選択します。

ここに画像の説明を入力

于 2015-12-24T22:59:35.820 に答える
0

私が間違っていなければ、あなたが使用しているReportDataSource ctorは最初のパラメータにデータソース、つまり名前付きデータソースを必要とします。これを提供していません。DataTable 名が必要です。

コードを次のように更新します。

DataTable dt = new DataTable();
dt.TableName = "myDataTable";
//Fill Datatable
ReportDataSource source = new ReportDataSource("myDataTable", dt);
于 2015-12-24T22:44:15.447 に答える
0

以下のようにソースを追加できます

LocalReport report = new LocalReport();

string startupPath = Environment.CurrentDirectory;
report.ReportPath = startupPath + @"\RDCLTemplate.rdlc";
report.Refresh();
于 2015-12-24T22:36:42.737 に答える