2011-04-18 29 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