2012-09-04 38 views
0

我有一個存儲過程將用於在reportviewer(VS2010中提供的那個)中創建報告。有4個參數 - 開始日期,結束日期 - 單個參數。 多值參數 - 狀態(6種可能的選擇), 位置(250種可能的選擇)。具有多個參數的ReportViewer

我無法確定對其進行編碼的正確方法,以便報告將顯示日期範圍內所有項目的所需的各種狀態/位置。

例如:顯示(開始日期)2012年7月1日和(結束日期)9/3/2012之間所有來自Hazleton或Butler的(位置)並且(狀態)可用或不可用的部分。

的代碼來調用存儲過程:

public DataTable StatusRpt(DateTime StartDate, DateTime EndDate) 
{ 
    SQLCON = new SqlConnection(connectionString); 
    SQLCON.Open(); 
    SQLCommand = new SqlCommand("spStatusRpt",SQLCON); 
    SQLCommand.CommandType = CommandType.Text; 
    SQLCommand.Parameters.Add("@StartDate", SqlDbType.Date).Value = StartDate; 
    SQLCommand.Parameters.Add("@EndDate", SqlDbType.Date).Value = EndDate; 
    //SQLCommand.Parameters.Add("@Status", SqlDbType.Int).Value = Status; 
    //SQLCommand.Parameters.Add("@OrgName", SqlDbType.VarChar).Value = OrgName; 

    SqlDataAdapter adapter = new SqlDataAdapter(SQLCommand); 
    DataTable Detailtable = new DataTable(); 
    adapter.Fill(Detailtable); 

    return Detailtable; 
} 

,這裏是我的「的onClick」事件

protected void btnStatusReport_OnClick(object sender, EventArgs e) 
{ 
    int Status = Convert.ToInt32(lbxStatus.SelectedValue); 
    string OrgName = lbxLocations.SelectedValue; 
    DateTime StartDate = Convert.ToDateTime(CalStart.SelectedDate); 
    DateTime EndDate = Convert.ToDateTime(CalEnd.SelectedDate); 
    lblPrint.Visible = true; 
    DataTable DetailTable = equip.StatusRpt(StartDate, EndDate); 

    this.RV1.Reset(); 
    this.RV1.LocalReport.DataSources.Clear(); 
    this.RV1.LocalReport.ReportPath = "Reports/StatusReport.rdlc"; 
    ReportDataSource rds = new ReportDataSource("StatusDS", DetailTable); 
    this.RV1.LocalReport.DataSources.Add(rds); 
    this.RV1.DataBind(); 
} 

我做了一些研究,但一切我發現是指使用SSRS 。如果有人能告訴我如何通過代碼應用過濾器,我可以過濾。

非常感謝您的幫助。 Cindy

+0

您可能需要爲此問題添加'sql'標記 –

回答

0

由於您使用的是客戶端報告(RDLC),請記住您是生成報告使用的數據的人員。我相信你可以將一個參數傳遞給報告並使用它來過濾顯示的數據,但你肯定不需要。

在過去,我使用服務器端報告(RDL)完成了這種事情。在這種情況下,我將逗號分隔的字符串傳遞給存儲過程。在這個過程中,我分解了它,將它插入到一個臨時表中,並與我的數據集結合在一起,過濾了結果。如果您有很多行,並且通常只會輸出其中的一部分,那麼您需要在該過程中執行此操作。如果您想在某個時候將此報告移到服務器端,這也可能是更好的方法。

如果你沒有很多行,那麼在你的代碼中過濾它可能就簡單了。你可以爲此使用LINQ(關於在DataTable上使用LINQ,請參閱this question)。請記住,您可以使用任何IEnumerable通過ReportDataSet傳入報表。

+0

由於存在多種選擇,因此不確定如何在此實例中應用Linq查詢。例如;如果選擇「可用」和「修復」和「失蹤」狀態,我將如何同時過濾所有3個?你給的Linq例子是一個簡單的字段= this。 –

+0

@Cindy IN Linq,你通常會得到一個集合(列表 mychoices)與所選擇的選項並逆轉你的邏輯:.Where(r => mychoices.Contains(r.Status)) –