【问题标题】:How to create a dynamic query in a local report(.rdlc) in c#如何在 C# 的本地报告(.rdlc)中创建动态查询
【发布时间】:2014-03-30 12:20:46
【问题描述】:

在我的应用程序中,我有 3 个记录不同的 report.rdlc 文件 我正在使用选项按钮、复选框和组合框值的表单创建查询

string qry = "";
SqlCeConnection cnn = new 

SqlCeConnection(Properties.Settings.Default.ConnectionString.ToString());
    SqlCeCommand cmd = new SqlCeCommand();

    if (radioButton1.Checked == true)
    {
        qry = @"Select Did,Cid,Source,Destination,Sid,cost,sdate,Driver.fname+' '+Driver.lname as driver,payed from Service,Driver where Service.Did=Driver.id";
    }
    else if (radioButton2.Checked == true)
    {
        button3.Enabled = true;
        qry = @"Select Did,Cid,Source,Destination,Sid,cost,sdate,Driver.fname+' '+Driver.lname as driver,payed from Service,Driver where Service.Did=Driver.id and Did=@param ";

        cmd.Parameters.Add("@param", CmbDriver.SelectedValue);
    }

    if (payedRB.Checked == true)
    {
        qry += @" and Service.payed=1";
    }
    else if (notpayedRB.Checked == true)
    {
        qry += @" and Service.payed=0";
    }

    if (txtDate1.Text != "" && txtDate2.Text != "")
    {
        qry += @" and Service.sdate between @pdate1 AND @pdate2";
        cmd.Parameters.Add("@pdate1", SqlDbType.NVarChar, 20).Value = txtDate1.Text.Trim();
        cmd.Parameters.Add("@pdate2", SqlDbType.NVarChar, 20).Value = txtDate2.Text.Trim();
        state = 3;
    }
    else if (txtDate1.Text != "")
    {
        qry += @" and Service.sdate >= @pdate1";
        cmd.Parameters.Add("@pdate1", SqlDbType.NVarChar, 20).Value = txtDate1.Text.Trim();
        state = 1;
    }
    else if (txtDate2.Text != "")
    {
        qry += @" and Service.sdate <= @pdate2";
        cmd.Parameters.Add("@pdate2", SqlDbType.NVarChar, 20).Value = txtDate2.Text.Trim();
        state = 2;
    }

    if (activdr.Checked == true)
    {
        qry += @" and Driver.isActive=1";
    }
    else
    {
        qry += @" and Driver.isActive=0";
    }

    qry += @" ORDER BY Service.sdate desc,Service.Sid desc";

    cmd.Connection = cnn;
    cmd.CommandText = qry;
    SqlCeDataAdapter adapter = new SqlCeDataAdapter(cmd);


                cnn.Open();

                adapter.Fill(dt);......

我在选项按钮事件中使用了报告类型变量来了解哪个 报告将显示在报告查看器中。并将选定的记录设置为 数据网格查看器

我的报告从与记录兼容的临时表中获取数据 场地。在此之前我插入所有记录(将在报告中打印 查看器)进入临时表;

如何在没有临时表的情况下将记录转入报表;

【问题讨论】:

    标签: c# sdf localreport dynamic-queries


    【解决方案1】:

    在本地报告中,不可能让报告本身查询数据库。您的应用程序需要查询数据库并将结果作为数据源传递给报表。

    您现在需要填写一个数据集并将其作为DataSource 传递给报告。报表需要定义相应的数据源来为字段提供值。

    【讨论】:

    • 我的代码中有 dt 数据表。现在如何通过数据源和数据集将这个数据表传递给本地报告,例如数据库中的任何表。或其他方式?请告诉我参考资料或代码.. 非常感谢
    • 你谷歌了吗?搜索词“c# rdlc dataset”在 StackOverflow 上至少显示 4 个结果。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多