我正在开发一个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。所以我不需要同时存储两个存储过程信息,所以我认为我可以重用相同的SQL连接。
好的,我找到了问题所在。如果我只是在Where子句中注释掉Level语句,它确实会返回数据。所以我唯一改变的是我的SQL代码中的一行,它的工作原理。这意味着缺少数据必须是由于数据类型不兼容,不是吗?有什么问题?
答案 0 :(得分:0)
我认为问题是你的代码甚至没有编译。在开始时查看发布的页面,我们看到:
End If
Main
End Sub
这不是有效的VB。您正在运行旧版本的代码。这也是你无法调试它的原因。您没有当前的设置断点。