【问题标题】:loading multiple records in rdlc from dataset从数据集中加载 rdlc 中的多条记录
【发布时间】:2014-08-28 10:47:56
【问题描述】:

我处于非常复杂的情况之间。我正在用仅来自存储过程的一条记录填充报告,该记录只需要一个参数并根据它选择记录,例如@投诉代码。现在要求已经改变,它应该加载多个记录,即我有两个日期文本框,它们只选择介于这些日期之间的投诉代码,例如20 个投诉代码,现在我的 rdlc 应该显示已加载到数据集中的所有投诉代码的所有记录。

为了让我的问题变得简单: 1.输入2个日期,点击搜索,在日期范围内加载多个投诉代码并放入数据集中。 2. 现在我想从存储过程中填充数据集,它只需要一个参数,即投诉代码并加载 rdlc 报告中的所有记录,如何?

代码:

protected void btnGenReport_Click(object sender, EventArgs e)
    {

        try
        {


            DateTime fromDate = DateTime.ParseExact(txtFromDate.Text, "dd/MMM/yyyy", null);
            DateTime toDate = DateTime.ParseExact(txtToDate.Text, "dd/MMM/yyyy", null);
            DataTable dt_temp = MyComplaints.SearchAllComplaintByDate(fromDate, toDate);

            ReportViewer1.ProcessingMode = ProcessingMode.Local;
            ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reports/Report_Complaints24Hours_Sdpo.rdlc");
            string ComplaintCode = Convert.ToString(txtComplaintCode.Text);
            DataTable dt = ManageRecievedMessage.Report_Complaints24Hours_Sdpo(ComplaintCode);

            if (dt.Rows.Count <= 0)
            {
                HiddenFieldSetMessage.Value = "WrongDatesComb";
                HiddenFieldShowMessage.Value = "True";
                ReportViewer1.Visible = false;
            }
            else
            {
                ReportDataSource rpds = new ReportDataSource("DataSet1", dt);
                ReportViewer1.LocalReport.DataSources.Clear();
                ReportViewer1.LocalReport.DataSources.Add(rpds);
                ReportViewer1.Visible = true;
            }

        }

【问题讨论】:

    标签: c# sql asp.net .net loops


    【解决方案1】:

    简单的方法是 制作一个带有四个参数的存储过程,例如

     Create procedure searchComplaint @complaintId=null varchar(50),@startDate=null date,@endDate=null date,@queryType=null 
     AS Begin 
    if(@queryType=='fetchFromID')
     Begin
     select * from record_Tbl where complaintId=@complaintId 
    End    
    if(@queryType=='fetchDateWise') 
    Begin  
    select * from record_Tbl where date between @startdate and @endDAte  
        End 
    
     END
    

    选择queryType参数的原因

    如果您想从 Only Complaint Id 获取数据,请使用 @querytype value="fetchFromID" else @querytype value="fetchDateWise" 调用存储过程

    然后存储过程根据查询类型根据 if 条件自动运行该查询..您将始终得到结果.. 所以唯一的概念是从存储过程中一次运行一个查询.. 只需将其他参数作为普通的 id,startdate,enddate 传递,用户已指定 Decider 只是 @queryType 参数

    那么如何传递不同的@queryType 参数

    使用单选按钮 1.仅通过ID搜索 2. 按日期搜索

    IF(option1) 然后 queryType="fetchFromID" 别的 queryType="fetchDateWise"


    希望对你有所帮助。如果您发现任何问题或困惑,请随时再次询问:)

    【讨论】:

    • 非常感谢先生,但我的问题不是这个,问题是我从另一个表加载 ComplaintCodes 然后将这些代码 1 一个传递以从另一个表加载另一个记录
    • 为什么一次传递一个值你可以在sql查询中使用“in”关键字 Like select ... from ... where id in (--your all values--)
    • 这个很简单,在sql查询中使用“in”。试试用in语句。 :) 希望它能解决你的问题
    猜你喜欢
    • 2020-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 2020-08-27
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    相关资源
    最近更新 更多