0

こんにちは、開発者の皆様、これは Crystal レポートを生成するための関数です。これは、レポート名と ReportQuery を入力パラメータとして受け取り、データセットを生成します。このデータセットを使用して、レポートをどのようにデザインできますか??これは実行時に生成されるためです、ReportDesign を生成するためにどのようにアクセスできますか??

public void fnLoadDataToReport(string rptName, string rptQuery)
{
    try
    {
        DataSet myDS=new DataSet();
//      crReportDocument.Load(Server.MapPath("Reports\" & RptName), OpenReportMethod.OpenReportByTempCopy);
        crReportDocument.Load(Server.MapPath("Reports\\" + rptName ));
        SqlConnection myConnection=new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ConnectionString);
        SqlCommand myCommand=new SqlCommand(rptQuery,myConnection);
        SqlDataAdapter MyDA=new SqlDataAdapter(myCommand);
        MyDA.Fill(myDS,"ReportTable");
        crReportDocument.SetDataSource(myDS);
        crvReportGeneration.ReportSource=crReportDocument;
        crvReportGeneration.ShowFirstPage();
    }
    catch(Exception ex)
    {
        Response.Write(ex.Message);
    }
}

どんな助けでもかなりです....!

4

2 に答える 2

1

レポートをデザインするために必要なのは、データセットのXMLスキーマ定義だけです。これは、次のコードで実現できます。

private void WriteSchemaToFile(DataSet thisDataSet){
   // Set the file path and name. Modify this for your purposes.
   string filename="mySchema.xml";
   // Write the schema to the file.
   thisDataSet.WriteXmlSchema(filename);
}

上記で作成したファイルをプロジェクトに追加します。

レポートをデザインする際に、[データベース エキスパート]を選択し、[プロジェクト] の下にある xml ファイルを選択します。それを追加します (テーブルやビューを追加するのと同じように)。

これで準備完了です。残りの手順は同じです。

XSD スキーマの名前とデータセット内のテーブル名が正確に一致していることを確認してください。

于 2012-04-18T20:49:55.853 に答える
0

レポートのソースとして DataSet を使用している理由。その代わりに、ストアド プロシージャをソースとして使用すると、問題が解決し、メンテナンスもはるかに簡単になります。

于 2012-04-18T18:08:48.923 に答える