gpt4 book ai didi

c# - 将 sql 参数值传递给 devexpress 报告?

转载 作者:可可西里 更新时间:2023-11-01 09:15:22 25 4
gpt4 key购买 nike

我想将一个 sql 参数从用户表单传递到我的报表类,但它不起作用并且它不创建报表,当我在向报表类添加 ID 参数后再次打开报表设计器选项卡时它刷新报表并删除我的组件。

问题是什么?

这是我的报告课:

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 ID=@ID";
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

这是我的使命:

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

最佳答案

我猜您想 (1) 单击按钮,(2) 传递一个 ID,然后 (3) 打开报告,其内容取决于该 ID。所以这就是我做的方式,(我不确定是否有其他方式,因为 devexpress 不是开源的):

  1. 设计您的数据集,它仅包含您想使用 Visual Studio 的数据集工具显示的信息。即 id、名称、地址、..... 命名该数据集 = ReportDataset。该数据集有 1 个名为 MyTable 的表。
  2. 使用 GUI 工具设计名为 MyReport 的报表(记得选择 XtraReport),并选择数据源 = ReportDataset,不要编辑 GUI 工具生成的代码。只需使用 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 ID=@ID";
    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 中重用自己的数据集来使其更容易。希望这会有所帮助。

关于c# - 将 sql 参数值传递给 devexpress 报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36186502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com