2014-08-28 88 views
0

我处于非常复杂的情况之间。我只从一个只需要一个参数的存储过程填充一条记录并根据它选择记录,例如, @complaintCode。现在需求已经改变,它应该加载多个记录,即,我有两个日期文本框,它们只选择落在这些日期之间的投诉代码,例如20个投诉代码,现在我的rdlc应显示已加载到数据集中的所有投诉代码的所有记录。从数据集中加载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; 
      } 

     } 

回答

0

简单的方法将是 做一个商店的过程,它需要四个参数,如

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 [email protected] 
End  
if(@queryType=='fetchDateWise') 
Begin 
select * from record_Tbl where date between @startdate and @endDAte 
    End 

END 

理由来选择你要获取数据的查询类型参数

从唯一的投诉ID基础调用存储过程@querytype值=“fetchFromID”其他@querytype值=“fetchDateWise”

然后存储过程根据查询类型按照条件自动运行该查询,并且您将始终得到结果.. 所以只有概念是这样从一个存储过程一次运行一个查询.. 只要通过其他参数如正常ID,开始日期,结束日期哪个用户spplied判定器是仅@queryType参数

因此,如何通过ID来传递不同@queryType参数

使用无线电单选按钮 1.Search仅 2 。按日期搜索

IF(选项1),那么查询类型= “fetchFromID” 其他 查询类型= “fetchDateWise”


我希望这会帮助你。如果你发现任何问题或困惑随时再问:)

+0

谢谢很多先生,但我的问题不是这个,问题是,我从另一个表加载ComplaintCode然后通过这些代码1加载另一个记录另一个表 – user3518032 2014-08-28 11:43:53

+0

为什么每次都要传递一个值你可以在sql查询中使用“in”关键字 Like select ... from ... where id in(--your all values--) – yogi970 2014-08-28 11:48:50

+0

这很简单在sql查询中使用“in”。尝试在声明中使用。 :)希望它能解决你的问题 – yogi970 2014-08-28 11:50:17

相关问题