0

私は報告するのが初めてです。MicrosoftaReportViewr を使用してレポートを表示しています。そのために、データセットを作成して入力しました。次に、そのデータセットを reportviewr1 のソースとして提供しようとします。しかし、実際のコーディングは取得できませんでした。私のコードは

if (cbReprt.Text == "FirmDetails")
{
            ReportDocument rpt = new ReportDocument();

rpt.Load("C:\\Users\\ALEN\\Desktop\\Merchant\\MerchantAssociation\\MerchantAssociation\\CrystalReport1.rpt");

SqlConnection myCon;
SqlDataAdapter myAdapter;

DataSet1 myDataset = new DataSet1(); //The DataSet you created.

           myCon = new SqlConnection("Data Source=202.88.231.102;Initial Catalog=dbs_Merchant;Persist Security Info=True;User ID=sa;Password=abc123*");

           SqlCommand cmd3 = new SqlCommand("select * from View1", myCon);
           cmd3.CommandType = CommandType.StoredProcedure;

           myAdapter = new SqlDataAdapter(cmd3);
           myAdapter.Fill(myDataset, "View1");
           rpt.SetDataSource(myDataset);
           reportViewer1.LocalReport.DataSources= rpt;
          reportViewer1.RefreshReport();
        }

しかし、私は reportViewer1.LocalReport.DataSources= rpt;を報告します。エラーを表示しています...特別な名前空間が必要かどうか?

4

1 に答える 1

1

reportviewer コントロールに DataSource を使用する方法は次のとおりです。

var myRds = new ReportDataSource("NameOfDataSourceDefinedInTheReport", myDataSet);
reportViewer1.LocalReport.DataSources.Add(myRds);

レポートは SSRS 形式である必要があることに注意してください。ReportViewer コントロール 2010 を使用している場合は、SSRS 2008 以降の形式である必要があります (2005 は非推奨です)。

「NameOfDataSourceDefinedInTheReport」という名前は、ロードするデータの実際のレポートで定義されているものと同じである必要があり、もちろん、データの構造はレポートで定義されているものと同じである必要があります。

于 2012-12-05T08:44:37.723 に答える