2016-03-23 19 views
10

は、私は私のレポートクラスにユーザーフォームからSQLパラメータを渡したいが、それは動作していないと、それはレポートを作成していないと私はレポートクラスにID引数を追加した後、再びレポートデザイナ]タブを開いたとき、それはレポートを更新し、私のコンポーネントを削除してください。sqlパラメータの値を渡してレポートをdevexpressにしますか?

何が問題ですか?ここで

は私のレポートクラスです:

public SodoorZemanatName(long ID) 
    { 
     InitializeComponent(ID); 
    } 

    protected override void Dispose(bool disposing) 
    { 
     if (disposing && (components != null)) 
     { 
      components.Dispose(); 
     } 
     base.Dispose(disposing); 
    } 

    #region Designer generated code 
    private void InitializeComponent(long ID) 
    { 
      this.components = new System.ComponentModel.Container(); 
      DevExpress.DataAccess.Sql.CustomSqlQuery customSqlQuery1 = new DevExpress.DataAccess.Sql.CustomSqlQuery(); 
      DevExpress.DataAccess.Sql.QueryParameter queryParameter1 = new DevExpress.DataAccess.Sql.QueryParameter(); 
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SodoorZemanatName)); 
      this.topMarginBand1 = new DevExpress.XtraReports.UI.TopMarginBand(); 
      this.detailBand1 = new DevExpress.XtraReports.UI.DetailBand(); 
      this.bottomMarginBand1 = new DevExpress.XtraReports.UI.BottomMarginBand(); 
      this.sqlDataSource2 = new DevExpress.DataAccess.Sql.SqlDataSource(this.components); 
      ((System.ComponentModel.ISupportInitialize)(this)).BeginInit(); 
      this.topMarginBand1.HeightF = 100F; 
      this.topMarginBand1.Name = "topMarginBand1"; 
      this.detailBand1.HeightF = 100F; 
      this.detailBand1.Name = "detailBand1"; 
      this.bottomMarginBand1.HeightF = 100F; 
      this.bottomMarginBand1.Name = "bottomMarginBand1"; 
      this.sqlDataSource2.ConnectionName = "Context"; 
      this.sqlDataSource2.Name = "sqlDataSource2"; 
      customSqlQuery1.Name = "Query"; 
      queryParameter1.Name = "ID"; 
      queryParameter1.Type = typeof(long); 
      queryParameter1.ValueInfo = "0"; 
      queryParameter1.Value = ID; 
      customSqlQuery1.Parameters.Add(queryParameter1); 
      customSqlQuery1.Sql = "select * from LG_Garanti where [email protected]"; 
      this.sqlDataSource2.Queries.AddRange(new DevExpress.DataAccess.Sql.SqlQuery[] { 
      customSqlQuery1}); 
      this.sqlDataSource2.ResultSchemaSerializable = resources.GetString("sqlDataSource2.ResultSchemaSerializable"); 
    this.Bands.AddRange(new DevExpress.XtraReports.UI.Band[] { 
    this.topMarginBand1, 
    this.detailBand1, 
    this.bottomMarginBand1}); 
    this.ComponentStorage.AddRange(new System.ComponentModel.IComponent[] { 
    this.sqlDataSource2}); 
    this.DataSource = this.sqlDataSource2; 
    this.Version = "15.2"; 
    ((System.ComponentModel.ISupportInitialize)(this)).EndInit(); 
} 
#endregion 

そして、ここで私の呼び出しです:私はあなたが(1)ボタンをクリックします推測

SodoorZemanatName report = new SodoorZemanatName(1); 
ASPxDocumentViewer1.ReportTypeName = "SodoorZemanatName"; 
ASPxDocumentViewer1.Report = report; 
+0

私はあなたが個別にレポートを設計する必要があると思います。 '新しいDevExpress.XtraReports.UI.XtraReports();を使用するだけでは、データソースの使い方やデータの表示方法がわからないことがあります。 'DevExpress.XtraReports.UI.XtraReportレポートは=新しいyour_report_design_class();' 私は過去にこの種のものを使用し、私はその背後にある私のコードで – minhhn2910

答えて

1

、(2)(その後、IDを渡します3)レポートを開くにはそのIDに依存するコンテンツがある。だから、これは私がやった方法、(私はDevExpress社がオープンソースではないので、他の方法があるかわからない)です:

  1. データセットを設計し、それはあなたがデータセットを使用して表示したいだけの情報が含まれていますVisual Studioのツール。 id、name、address、.....そのデータセットの名前をReportDatasetとします。そのデータセットにはMyTableという1つのテーブルがあります。
  2. ReportDatasetは、GUIツールで生成されたコードを編集しないこと=(XtraReportを選択することを忘れないでください)GUIツールを使用してMyReportという名前のレポートを設計して、データソースを選択します。ただ、GUIを使用して、ラベルを追加ReportDatasetから値を追加する&クリックをクリックしてください。
  3. あなたは、ウィンドウのフォームまたは何を形成するには、以下の(あなたがあなたの質問の最後のスニペットで「呼び出し」)button_clickイベントによってトリガ関数内でなければなりません:上記

    DataSet new_ds = new DataSet(); 
    ReportDataset.MyTable runtime_data = new ReportDataset.MyTable(); 
    //get data from your database according to ID, Row by row 
    //then add them to the runtime_data table 
    //in your case, add all the result of "select * from LG_Garanti where [email protected]"; 
    runtime_data.Rows.Add(new object[] {.blah blah..});// just add row, use whatever method you like 
    new_ds.Tables.Add(runtime_data); 
    //from this point, new_ds contains runtime data of the row(s) you want ID. 
    //now just link that dynamic dataset to your designed report 
    MyReport my_report = new MyReport(); 
    my_report.DataSource = new_ds; 
    // Show the print preview or do whatever you want 
    ReportPrintTool printTool = new ReportPrintTool(my_report); 
    printTool.ShowRibbonPreviewDialog(); 
    

報告書は、異なるテーブルの混合物を用いて、独自のデータセットを使用することができるので、...あなたはそれが簡単にこのことができますステップ1希望で独自のデータセットを再利用することで作ることができ、それをより柔軟にすることです。

+0

にデータソースを割り当てる前に私のデザインを使用して新しいレポートを作成する必要がありますレポートデザイナーで作成したため、ReportDatasetにアクセスできません。 –

+0

混乱してしまって残念ですが、外部にデータソースを作成して(.xsdファイルを使用して)レポートに割り当てると、Visual Studioにアクセスできなくなりました。 https://documentation.devexpress.com/#XtraReports/CustomDocument4797 – minhhn2910

+0

データセットを作成し、次のように.xsdファイルとして保存します。https://msdn.microsoft.com/en-us/library/ms171897.aspx – minhhn2910

関連する問題