2011-04-17 230 views
0

我正在开发一个ASPX网页,以通过VB返回两个SQL存储过程的结果。当我执行这两个存储的特效时,它们都会返回有效的数据。但由于某种原因,当我运行此报告时,它不会返回任何错误,但是,它也不会返回任何记录/数据!为什么没有数据显示?

此外,由于某种原因我无法调试它,尽管我可以设置断点!这是使用VS 2008,但我认为我无法调试的原因是我相信这是一个仅适用于SSRS和SSIS的有限版本。

这里是我的代码的摘录:

<HTML> 
    <SCRIPT LANGUAGE="VB" RUNAT="Server"> 
     Sub Page_Load(Sender as Object, E as EventArgs) 
      If Not IsPostback Then 
       Dim TheMonthDate As Date = DateAdd(DateInterval.Month, -1, Today) 
       calStartDate.SelectedDate = CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/yyyy") 
       calEndDate.SelectedDate = GlobalFunctions.GlobalF.MonthLastDate(CDate((TheMonthDate.Month) & "/1/" & Year(TheMonthDate)).ToString("MM/dd/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" 



    End If 
       Main 
      End Sub 

      Sub Main()   
       '------------------------- Query database and get arrays for the chart and bind query results to datagrid ---------------------------------------- 

       Dim FirstMonthDate as date = calStartDate.SelectedDate 
       Dim LastMonthDate as date = calEndDate.SelectedDate 

       Dim TheLevel As Integer 
       Dim TitleLevel as String 

       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 DSPageData as new System.Data.DataSet 
       DSPageData = GlobalFunctions.GlobalF.GetComplaintTrending2(FirstMonthDate, LastMonthDate, TheLevel) 
    ... 
       Dim DSDetails As New System.Data.DataSet 
       DSDetails = GlobalFunctions.GlobalF.GetComplaintTrendingDetails2(FirstMonthDate, LastMonthDate, TheLevel) 
       dgTable.DataSource = DSDetails 
       dgTable.DataBind() 

凡在我Global.vb文件我有:

  'Added by Ryan on 4/17/11 
     Public Shared Function GetComplaintTrending2(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("ComplaintTrending2", conn), _ 
      da As New SQLDataAdapter(cmd) 
       cmd.CommandType = CommandType.StoredProcedure 
       cmd.Parameters.AddRange(param) 

       da.Fill(DSPageData) 
      End Using 

      Return DSPageData 
     End Function 
     'Added by Ryan on 4/17/11 
     Public Shared Function GetComplaintTrendingDetails2(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("ComplaintTrendingDetails2", conn), _ 
      da As New SQLDataAdapter(cmd) 
       cmd.CommandType = CommandType.StoredProcedure 
       cmd.Parameters.AddRange(param) 

       da.Fill(DSPageData) 
      End Using 

      Return DSPageData 
     End Function 

而且这些存储的特效被定义为:

CREATE PROCEDURE [dbo].[ComplaintTrendingDetails2] 
--DECLARE 
@FirstMonthDate DATETIME, 
@LastMonthDate DATETIME, 
@TheLevel INT 

AS 
    SET NOCOUNT ON; 

--ComplaintTrendingDetails2 '2/1/11', '2/28/11 23:59:59', 2 
--SET @FirstMonthDate = '2/1/11' 
--SET @LastMonthDate = '2/28/11 23:59:59' 
--SET @TheLevel = '2' 

SELECT DISTINCT  
    A.QXP_EXCEPTION_NO, A.[LEVEL], A.pRE,  
    A.QXP_REPORT_DATE, A.CLOSE_DATE, A.EPA_PRD_NAME,  
    A.EPA_PRD_CODE, A.EPL_LOT_NUMBER,  
    A.QXP_SHORT_DESC, A.QXP_DESCRIPTION,  
    A.QXP_RESOLUTION_DESC, A.CXP_CLIENT_NAME, A.Country,  
    C.PRODUCT, C.PRODUCT_GROUP, C.PRODUCT_ORG_UNIT,  
    B.DOC_DOCUMENT_NO, A.TICKET_NUM, A.CENTER_NUM,  
    A.COUNTRY_CODE, A.QXP_ID, B.IRF_QEI_ID 

    FROM ALL_COMPLAINTS A LEFT OUTER JOIN  
    SMARTSOLVE.V_QXP_ISSUE_REF B ON A.QXP_ID = B.IRF_QXP_ID LEFT OUTER JOIN  
    MANUAL.PRODUCTS C ON A.EPA_PRD_CODE = C.LIST_NUMBER  
    LEFT OUTER JOIN SMARTSOLVE.V_CXP_CUSTOMER_PXP D ON A.QXP_ID = D.QXP_ID  
    WHERE A.QXP_REPORT_DATE >= @FirstMonthDate AND A.QXP_REPORT_DATE <= @LastMonthDate 
    AND (A.QXP_SHORT_DESC <> 'Design Control') AND LEVEL = @TheLevel  
    AND (D.QXP_EXCEPTION_TYPE <> 'Non-Diagnostic' OR D.QXP_EXCEPTION_TYPE IS NULL)  
ORDER BY 4 

and 

--ALTER PROCEDURE [dbo].[ComplaintTrending2] 
DECLARE 
@FirstMonthDate DATETIME, 
@LastMonthDate DATETIME, 
@TheLevel INT 

--AS 
-- SET NOCOUNT ON; 

--ComplaintTrending2 '2/1/11', '2/28/11 23:59:59', 2 
SET @FirstMonthDate = '2/1/11' 
SET @LastMonthDate = '2/28/11 23:59:59' 
SET @TheLevel = '2' 

SELECT 
CASE ISNULL(PRODUCT_GROUP, '') WHEN '' THEN 'Unspecified' ELSE PRODUCT_GROUP END AS PRODUCT_GROUP, 
COUNT(DISTINCT A.QXP_EXCEPTION_NO) AS CountOfTickets 
    FROM ALL_COMPLAINTS a 
    LEFT OUTER JOIN MANUAL.PRODUCTS b ON a.EPA_PRD_CODE = b.LIST_NUMBER 
    LEFT OUTER JOIN SMARTSOLVE.V_CXP_CUSTOMER_PXP c ON a.QXP_ID = c.QXP_ID 
    WHERE a.QXP_REPORT_DATE >= @FirstMonthDate AND a.QXP_REPORT_DATE <= @LastMonthDate 
    AND (a.QXP_SHORT_DESC <> 'Design Control') AND LEVEL = @TheLevel 
    AND (c.QXP_EXCEPTION_TYPE <> 'Non-Diagnostic' OR c.QXP_EXCEPTION_TYPE IS NULL) 
GROUP BY PRODUCT_GROUP 
ORDER BY COUNT(DISTINCT a.QXP_EXCEPTION_NO) DESC 

问题是由于这个网页对两个存储过程使用相同的SQL连接的事实吗?第一个proc应该首先返回,第二个proc应该在这个屏幕之后返回。所以我不需要同时存储proc信息,所以我想我可以重复使用相同的SQL连接。

好的,我找到了问题所在。如果我只是在Where子句中注释掉Level语句,它确实会返回数据。所以我唯一改变的是我的SQL代码中的一行,它的工作原理。这意味着缺少的数据必须是由于数据类型不兼容,否?问题是什么?

回答

0

我认为问题是你的代码甚至没有编译。在开始的页面右侧看到我们看到:

End If 
      Main 
     End Sub 

这是无效的VB。您正在运行您的代码的旧版本。这也是为什么你不能调试它。你目前没有设置断点。

+0

我不确定你的意思,因为使用相同代码的原始报告成功显示数据。 – salvationishere 2011-04-17 17:04:58

+0

你在原始和新的之间有什么变化? – Hogan 2011-04-17 18:30:05

0

我现在想通了这个问题。在我最后一段之后,我只需要做一些小改动。