C#数据不通过DataGrid SQL SP循环

时间:2016-10-19 16:22:20

标签: asp.net infragistics

我在这个相当大的项目中使用Infragistics WebDataGrid。当用户选择2个日期并且在10个WebDatagrids中的至少一个中显示程序集编号缺陷信息时,需要发生什么。大多数情况下,有2个或更多的缺陷信息。我将结果与旧的VB.NET窗体应用程序进行比较。我可以成功运行SP并获得结果,但是,只有一个数据网格填充结果,而不是其他应该包含信息的网格。我已删除连接详细信息以确保安全性。我提前感谢你的帮助。

C#代码                 private void MessageBox(string msg)                 {                 Page.Controls.Add(new LiteralControl(                 " window.alert('" + msg.Replace("'"," \'")+"& #39)&#34));                 }

            private void getDefects(string workArea, WebDataGrid webDG)
            {
            if (wdpStartDate.Text == "" || wdpEndDate.Text == "")
            {
            MessageBox("You must provide values for Start Date and End Date!");
            }
            else
            {
            //Create a connection to the SQL Server on IIS01.

            //Establishes the command structure for the stored procedure Top5Defects.
            SqlCommand cmd = new SqlCommand("dbo.Top5Defects", iis01Connection);
            cmd.CommandType = CommandType.StoredProcedure;

            //Establishes the required parameters to pass to the stored procedure.
            cmd.Parameters.AddWithValue("@StartDate", wdpStartDate.Date.ToShortDateString());
            cmd.Parameters.AddWithValue("@EndDate", wdpEndDate.Date.ToShortDateString());
            cmd.Parameters.AddWithValue("@Assembly", Assemblies.CurrentValue);
            cmd.Parameters.AddWithValue("@WorkArea", workArea);
            iis01Connection.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            webDG.DataSource = dr;
            webDG.DataBind();
            }
            }

            public void GetDefectHistory()
            {

            getDefects("SL", wdgSL);
            getDefects("PW", wdgPW);
            getDefects("SMT", wdgSMT);
            getDefects("SS/Wave", wdgSSWV);
            getDefects("AI", wdgAI);
            getDefects("ICT", wdgICT);
            getDefects("FT", wdgFT);
            getDefects("CC", wdgCC);
            getDefects("EM", wdgEM);
            getDefects("TC", wdgTC);
            }

            protected void btnResults_Click(object sender, EventArgs e)
            {
            GetDefectHistory();
            }

存储过程                 使用[EMSDatabase]                 走                 / ******对象:StoredProcedure [dbo]。[Top5Defects]脚本日期:10/18/2016 10:15:48 PM ****** /                 SET ANSI_NULLS ON                 走                 SET QUOTED_IDENTIFIER ON                 走                  - =============================================                  - 作者:Trent Adams>                  - 创建日期:2016年10月13日                  - 描述:EMSDatabase Top Defects的存储过程                  - =============================================                 更改程序[dbo]。[Top5缺陷]                 @StartDate DATETIME,                 @EndDate DATETIME,                 @Assembly VARCHAR(50),                 @WorkArea VARCHAR(50)

            AS
            --Declare @WorkArea as VARCHAR(50)
            --Set @WorkArea ='SL'

            BEGIN
            -- SET NOCOUNT ON added to prevent extra result sets from
            -- interfering with SELECT statements.
            SET NOCOUNT ON;

            SELECT Top 5 Sum(Quantity) AS 'Sum', DefectCode As Defect, PartInvolved AS Part 
            FROM EMSDefectHistory
            WHERE DateEntered Between @StartDate AND @EndDate
                AND Assembly = @Assembly
                AND WorkArea = @WorkArea
            GROUP BY DefectCode, PartInvolved 
            ORDER BY Sum(Quantity) DESC
            END

1 个答案:

答案 0 :(得分:0)

事实证明,在阅读VB.NET代码时,我是盲目的。由于功能测试(FT)和在线测试(ICT)使用不同的表格,我需要分别为这些FT / ICT创建方法。