通过传递更多的一个参数,根据过程在GridView中显示数据

时间:2015-05-05 10:29:58

标签: c# asp.net sql-server-2008

我有一个存储过程,我希望将结果放在DataGridView

如下图所示我有5个参数,我想每次只使用其中一个参数。其余的可以是空值。

例如:“我希望通过5种不同的方式进行过滤,但每次我只使用一个参数,如ID,对于第二种情况,我将按日期等过滤....”

我将从表单中的文本框传递数据。

我想要C#代码或直接从GridViewSqlDataSource执行此操作:

ALTER Procedure [dbo].[ValidatiorSelection]
(
        @ID int
        ,@Cisco int
        ,@Date date
        ,@Resoution varchar(60)
        ,@Type varchar(30) 
)
AS
BEGIN
    SET NOCOUNT ON;

    SELECT 
           [Justification_ID]
          ,[Justification_Cisco]
          ,[HC_AgentName]
          ,[HC_Q]
          ,[HC_Cisco]
          ,[HC_Site]
          ,[HC_SPV]
          ,[HC_TeamLeader]
          ,[Justification_Date_Of_Case]
          ,[Justification_AgentShift]
          ,[Justification_From]
          ,[Justification_To]
          ,[Justification_OT_Duration]
          ,[Justification_Justification]
          ,[Justification_Description]
          ,[Justification_Creator]
          ,[Justification_Approved_By]
          ,[Justification_Type]
          ,[Justification_Group_ID]
          ,[WFM_Specialeist]
          ,[WFM_Resolution]
          ,[WFM_Status]
          ,[WFM_Comment]
          ,CASE WHEN DateDiff("d",[Justification_Date_Of_Case],[Justification_DT])>2 then 'Exceeded 48 Hours' 
           else 'During 48 Hours'
           end as 'Time Status'
          ,[Justification_DT] as 'Open Time'
          ,[WFM_DT] as 'Close Time'
    FROM 
        [ZainJTA].[dbo].[TBL_WFM] 
    RIGHT JOIN 
        ([ZainJTA].[dbo].[TBL_Justification] 
    LEFT JOIN 
        [ZainJTA].[dbo].[TBL_HC] ON [TBL_Justification].[Justification_Cisco] = [TBL_HC].[HC_Cisco]) ON [TBL_WFM].[WFM_JustificationID] = [TBL_Justification].[Justification_ID]
    WHERE
        [TBL_Justification].Justification_ID = @ID  
        OR [TBL_Justification].Justification_Cisco = @Cisco 
        OR [TBL_Justification].Justification_Date_Of_Case = @Date
        OR [TBL_Justification].Justification_Type = @Type
        OR [TBL_WFM].[WFM_Resolution] = @Resoution     
    ORDER BY 
        [Justification_ID] DESC
END

1 个答案:

答案 0 :(得分:0)

这应该有用。

 <asp:SqlDataSource id="SqlDataSource1"
 runat="server"
 ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
    SelectCommandType="StoredProcedure"                
    SelectCommand="sp_lastnames">
     <SelectParameters>
            <asp:ControlParameter Name="Name" Type="String" ControlID="txtName" />
            </SelectParameters>
    </asp:SqlDataSource>