如何在C#中的本地报表(.rdlc)中创建动态查询 [英] How to create a dynamic query in a local report(.rdlc) in c#

查看:303
本文介绍了如何在C#中的本地报表(.rdlc)中创建动态查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my application I have 3 report.rdlc files that records are not different I am creating a query in a form with options buttons, checkboxes and combobox values

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);......

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

I used reporttype variable in option buttons event to know which report will be shown in report viewer. and set selected records to data grid viewer

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

my reports get data from a temp table that is compatible with record's field. before this I insert all records( that will be printed in the report viewer) into temp table;

如何在没有临时表的情况下将记录转移到报告中?

How can I transfer records into reports without temp table;

推荐答案

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

In local reports it is not possible to have the report itself query the database. Your application needs to query the database and pass the results to the report as a data source.

您现在需要填写数据集,并将其作为DataSource传递给报告.该报告需要定义相应的数据源,以为字段提供值.

You need to fill a data set now and pass this as a DataSource to the report. The report needs to define a respective data source to provide values for the fields.

这篇关于如何在C#中的本地报表(.rdlc)中创建动态查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆