2014-08-28 22 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

相關問題