2

友人、私は c# を使用して単純なアプリケーションを開発しました。2 つの rdlc レポートがあります。

以下のコードを使用して、データソースをレポート ビューアーにバインドしました

 this.reportViewer1.LocalReport.ReportPath = @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\reports\reports\Report1.rdlc";
 reportViewer1.LocalReport.DataSources.Clear();
 reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("customer", dt.Tables[0])) ;
 this.reportViewer1.RefreshReport();

しかし、レポートが生成されると、データが表示されない空のレポートです。何か意見はありますか?

4

3 に答える 3

7

ウィザードでプロジェクトに .rdlc レポートを追加すると、デフォルトでデータセット名が'DataSet1'になります。新しいデータセットを動的にバインドする場合は、そのデータセットの名前を'DataSet1'にする必要があります。変更してみて、Table[0] にDataTypeが の元の dataType と一致するデータ (行) が含まれていることも確認してくださいDataSet1。DataType が一致しない場合、データは ReportViewer に表示されません。このコードを試してください:-

string exeFolder = (Path.GetDirectoryName(Application.StartupPath)).Substring(0, (Path.GetDirectoryName(Application.StartupPath)).Length - 3);
string reportPath = Path.Combine(exeFolder, @"Reports\SessionReport.rdlc");
Microsoft.Reporting.WinForms.ReportDataSource rds = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", yourDataSet.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.LocalReport.ReportPath = reportPath;
this.reportViewer1.RefreshReport();

.rdlc レポート (コア ロジック) の詳細については、次のリンクを参照 してください。データベースなしでレポート (RDLC) を作成するには?

于 2013-07-08T11:22:07.440 に答える
2

以下を試してみてください。データソース名が正しくないことが問題である可能性があります。

reportViewer1.LocalReport.DataSources.Add(new ReportDataSource(ds.DataSetName + "_" + ds.Tables[0].TableName, ds.Tables[0]));

rdlc ファイルの内容でデータセット名を確認できます。データセットの名前プロパティがコードで指定したものと一致することを確認してください。

于 2013-04-09T06:22:46.000 に答える
0

これは、オブジェクト バインディングを使用してデータを更新する方法です。 Form1.cs ファイルでは、次のようになります。

private myClass m_products = new Products();
public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           this.PaperBindingSource.DataSource = m_products.GetProducts();

this.PaperBindingSource.DataSourceが重要です。

于 2013-05-21T23:44:14.763 に答える