2011-04-18 104 views
0

我正在开发一个ASPX文件,它将SQL存储过程的结果返回到数据适配器中,然后显示在一个GridView中。但问题是SQL存储过程和Gridview之间的数字不匹配。它们很接近,但略微偏离千分之三。所以SQL存储过程给我0.199,但在Gridview中这个值= .203。它似乎也不是一个四舍五入的问题。另外,我查看了Gridview属性,但是我没有看到任何会导致这种情况的东西。这一列的所有值均以相同的余量关闭。ASPX文件输出不同于SQL存储过程

您可以推荐哪些故障排除步骤?我在VS 2008 Shell中为SSRS,SSIS使用VB。这里是我的代码从主ASPX文件:

<%@ Page Language="VB" Debug="true" Src="../Global.vb"%> 
<%@ Import Namespace="ChartDirector" %> 
<%@ Import Namespace="System.Data" %> 
<%@ Import Namespace="System.Data.OleDB" %> 
<%@ Import Namespace="System.Math" %> 
<%@ Import Namespace="System.Data.SqlClient" %> 
<%@ Register TagPrefix="chart" Namespace="ChartDirector" Assembly="netchartdir" %> 

<HTML> 
    <SCRIPT LANGUAGE="VB" RUNAT="Server"> 
     Sub Page_Load(Sender as Object, E as EventArgs) 
      If Not IsPostback Then 
       Dim YearDate as date = "1/ 1/05"    
       Dim arrYear as New ArrayList() 

       While YearDate <= Today 
        arrYear.Add(YearDate.ToString("yyyy")) 
        YearDate = YearDate.AddYears(1) 
       End While 

       dYear.DataSource = arrYear 
       dYear.DataBind() 
       dYear.SelectedValue = Today.AddMonths(-1).ToString("yyyy") 

       Dim arrLevel as New ArrayList() 

       arrLevel.Add("All") 
       arrLevel.Add("Inquiries") 
       arrLevel.Add("All Complaints") 
       arrLevel.Add("Elevated Complaints") 
       arrLevel.Add("Non-Elevated Complaints") 

       dLevel.DataSource = arrLevel 
       dLevel.DataBind() 
       dLevel.SelectedValue = "All Complaints" 

       '********* Set Month dropdown ************ 
       Dim EndMonth as Date 
       dim StartMonth as Date = "1/1/" & dYear.SelectedValue 
       Dim arrMonth as New ArrayList() 

       EndMonth = "12/1/" & dYear.SelectedValue 

       While StartMonth <= EndMonth 
        arrMonth.Add(MonthName(month(StartMonth))) 
        StartMonth = StartMonth.AddMonths(1) 
       End While 

       dMonth.DataSource = arrMonth 
       dMonth.DataBind() 

       If dYear.SelectedValue = Today.ToString("yyyy") then 
        dMonth.SelectedValue = MonthName(month(Today.AddMonths(-1))) 
       End If 

       Label1.Text = "Complaint Trending List" 
       btnExport.Visible = "false" 

      Else 
       Main() 
       btnExport.Visible = "true" 
      End If   
     End Sub 

     Sub Main()   
      Dim TheLevel As Integer 
      Dim TitleLevel As String 
      Dim FirstMonthDate As Date = dMonth.SelectedValue & "/1/" & dYear.SelectedValue 
      Dim LastMonthDate as date = GlobalFunctions.GlobalF.MonthLastDate(FirstMonthDate) 
      Dim arrMonthYear As New ArrayList() 

      Select Case dLevel.SelectedValue 
       Case "All" 
        TheLevel = 5 
        TitleLevel = "Inquiries and Complaints" 
       Case "Inquiries" 
        TheLevel = 0 
        TitleLevel = "Inquiries" 
       Case "All Complaints" 
        TheLevel = 3 
        TitleLevel = "All Complaints" 
       Case "Elevated Complaints" 
        TheLevel = 2 
        TitleLevel = "Elevated Complaints" 
       Case "Non-Elevated Complaints" 
        TheLevel = 1 
        TitleLevel = "Non-Elevated Complaints" 
      End Select 

      Dim dataPG As New System.Data.DataSet 
      Dim dataSD As New System.Data.DataSet 
      Dim dataPCHART As New System.Data.DataSet 

      PrintMessageGrid.DataSource = GlobalFunctions.GlobalF.GetComplaintTrendingList6(FirstMonthDate, LastMonthDate, TheLevel) 
      PrintMessageGrid.DataBind() 

      Dim ListDataTable As DataTable 
      Dim ListDataRow As DataRow 
      ListDataTable = New DataTable 

      ListDataTable.Columns.Add("Product Group") 
      ListDataTable.Columns.Add("Short Description") 
      ListDataTable.Columns.Add("p-value") 
      ListDataTable.Columns.Add("LCL") 
      ListDataTable.Columns.Add("UCL") 
      ListDataTable.Columns.Add("Six In A Row") 
      ListDataTable.Columns.Add("Exceeds Limits") 
      'ListDataTable.Columns.Add("Selected") 
      'ListDataTable.Columns.Add("Total") 

      Label1.Text = dMonth.SelectedValue & " " & dYear.SelectedValue & " Complaint Trending List" 
     End Sub 

     Sub PrintMessageGrid_RowDataBound(ByVal sender As Object, _ 
     ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) 
      If e.Row.RowType = DataControlRowType.DataRow Then 
       Dim exceeds_limits As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Exceeds_Limit")) 
       Dim six_in_a_row As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Six_In_A_Row")) 
       If exceeds_limits = 1 Or six_in_a_row = 1 Then 
        e.Row.BackColor = Drawing.Color.Red 
       End If 
      End If 
     End Sub 

     Private Sub btnExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
      GlobalFunctions.GlobalF.GridViewToExcel(PrintMessageGrid, Response) 
     End Sub 


    </SCRIPT> 
    <head> 
     <title>AMD QA Metrics</title> 
    </head> 
    <body onbeforeunload="LoadBusy();"> 
     <script language="javascript" src="../includes/CastleBusyBox.js"></script> 
     <div style="font-size:18pt; font-family:verdana; font-weight:bold"> 
      <asp:Label ID="Label1" runat="server"></asp:Label> 
     </div> 
     <hr style="color:#000080"/> 
     <form runat="Server" method="post" id="Form1"> 
      <table> 
       <tr><th>Month</th><th>Year</th><th>Level</th></tr> 
       <tr> 
        <td><ASP:DROPDOWNLIST id="dMonth" runat="Server" autopostback="false" /></td> 
        <td><ASP:DROPDOWNLIST id="dYear" runat="Server" autopostback="false" /></td> 
        <td><ASP:DROPDOWNLIST id="dLevel" runat="Server" autopostback="false" /></td> 
       </tr> 
      </table> 

      <asp:Button id="btnSubmit" runat="server" Text="submit" /> 
      <br /> 
      <br /> 
      <span onclick="busyBox.Enabled = false;"> 
       <asp:Button id="btnExport" runat="server" Text="Export List to Excel" onclick="btnExport_Click" autopostback="false" /> 
      </span> 
      <ASP:GridView id="PrintMessageGrid" runat="server" AUTOGENERATECOLUMNS="true" ShowHeader="true" OnRowDataBound="PrintMessageGrid_RowDataBound"> 
        <HEADERSTYLE BackColor = "#336699" ForeColor = "#ffffff" Font-Bold = "true" /> 
       </ASP:GridView> 
      <iframe id="BusyBoxIFrame" name="BusyBoxIFrame" frameBorder="0" scrolling="no" ondrop="return false;"> 
      </iframe> 
      <SCRIPT> 
       // Instantiate our BusyBox object 
       var busyBox = new BusyBox("BusyBoxIFrame", "busyBox", 4, "../Images/gears_ani_", ".gif", 125, 147, 207); 
      </SCRIPT> 
     </form> 
    </body> 
</HTML> 

而且global.vb文件的部分:

Namespace GlobalFunctions 
     Public Class GlobalF 

      'Added by Ryan on 4/14/11 
     Public Shared Function GetComplaintTrendingList6(ByVal FirstMonth As DateTime, ByVal LastMonth As DateTime, ByVal rowLevel As Integer) As DataSet 
      Dim DSPageData As New System.Data.DataSet 
      Dim param(2) As SqlClient.SqlParameter 

      param(0) = New SqlParameter("@FirstMonthDate", SqlDbType.DateTime) 
      param(0).Value = FirstMonth 
      param(1) = New SqlParameter("@LastMonthDate", SqlDbType.DateTime) 
      param(1).Value = LastMonth 
      param(2) = New SqlParameter("@TheLevel", SqlDbType.Int) 
      param(2).Value = rowLevel 

      ''# A Using block will ensure the .Dispose() method is called for these variables, even if an exception is thrown 
      ''# This is IMPORTANT - not disposing your connections properly can result in an unrespsonsive database 
      Using conn As New SQLConnection(ConfigurationSettings.AppSettings("AMDMetricsDevConnectionString")), _ 
      cmd As New SQLCommand("ComplaintTrendingList6", conn), _ 
      da As New SQLDataAdapter(cmd) 
       cmd.CommandType = CommandType.StoredProcedure 
       cmd.Parameters.AddRange(param) 

       da.Fill(DSPageData) 
      End Using 

      Return DSPageData 
     End Function 
... 
     Public Shared Function MonthLastDate(ByVal TheDate As Date) 
      Select Case TheDate.Month 
       Case 1, 3, 5, 7, 8, 10, 12 
        MonthLastDate = TheDate.Year & "-" & TheDate.Month & "-31" 
       Case 4, 6, 9, 11 
        MonthLastDate = TheDate.Year & "-" & TheDate.Month & "-30" 
       Case 2 
        If (CInt(TheDate.Year) Mod 4) = 0 Then 
         MonthLastDate = TheDate.Year & "-" & TheDate.Month & "-29" 
        Else 
         MonthLastDate = TheDate.Year & "-" & TheDate.Month & "-28" 
        End If 
      End Select 
     End Function 
+0

为什么这篇文章被拒绝投票,请在投票时提供反馈意见,这样海报可以在下一次改善他的帖子,或者编辑他们 – Ivo 2011-04-18 14:43:18

+0

我不明白为什么这是低票。我做错什么了吗?什么? – salvationishere 2011-04-18 14:47:52

回答

1

你将不得不调试到这找什么有问题的值在哪些步骤。

如果您在调试页面时直接查看GlobalFunctions.GlobalF.GetComplaintTrendingList6(FirstMonthDate, LastMonthDate, TheLevel)的结果,那么问题的数值会是什么样子?

如果您进入该功能并在填充后查看DSPageData的内容,数值的外观如何?

如果您使用给定参数从cmd获取命令,并直接在数据库上执行它,那么数值的外观如何?

如果您在数据库上运行跟踪并捕获为存储过程发送的实际执行命令,它是否与您认为应匹配的内容相符?在发送到服务器时手动运行它,看看结果如何。

+0

谢谢大卫。我想这样做,并已使用其他版本的VS.但是,这是shell,我似乎没有调试选项。我可以设置断点,但所有的调试功能都是灰色的。这可能是因为我只能创建SSAS/SSIS/SSRS项目。 – salvationishere 2011-04-18 14:57:28

+0

我不知道/如果我可以在数据库上运行跟踪或者使用此限制版本的VS – salvationishere 2011-04-18 15:00:57

+0

@salvationishere提到的其他任何事情:我没有使用该版本,但是我会_hope_有一些方法以某种方式进入这些断点。如果没有,你可能会留下一些可怜的人的调试,只需在运行时输出你需要的值给其他源。基本上只需添加大量的日志语句,然后运行代码即可。对于跟踪,您使用的是哪个数据库/版本?如果这是MS SQL Server,那么您应该安装或访问名为SQL Server Profiler的程序,即使它位于服务器上。 – David 2011-04-18 15:05:16