SQL不检索/显示所需的数据

时间:2014-09-02 01:17:35

标签: sql asp.net vb.net

所以我通过SQL检索数据,并将其用于语句页面。它有客户,日期,交易,借记,贷方和余额列。现在,当涉及到信用而非借记的交易时,它不显示。

E.G - http://oi57.tinypic.com/16m1yeq.jpg

检查上面的图片,您会看到信用证没有显示。 如果有问题显示为什么它没有显示,请帮助我!我知道代码中有一些东西可以修复" nDrTotal" &安培; nCrTotal

谢谢! 问题是......为什么借方表中没有显示负数? 这是我获取数据的代码 -

Function ApplyStatementDetails(ByVal sContent As String, ByVal sClientID As String, ByVal sDate As String, ByVal sSection As String) As String
    Dim sSQL As String, sOut As String, rsStatement As SqlDataReader, sHTML As String = "", iLines As Integer, iCount As Integer
    Dim nInvTotal As Double, n90Days As Double = 0, n60Days As Double = 0, n30Days As Double = 0, nCurrent As Double = 0, dCompareDate As Date
    Dim nBalance As Double = 0

    sOut = ApplyCompanyDetails(sContent)

    'response.write sSQl: response.end
    rsStatement = New SqlCommand(sSQL, cnStatemnt).ExecuteReader

    Dim bFirst As Boolean = True, sClient As String = "", sAddress As String = ""
    Dim nDRTotal As Double = 0, nCRTotal As Double = 0, nPaymentsAlloc As Double = 0
    Do While rsStatement.Read
        If bFirst Then
            iCount = 0
            sClient = EmptyIfNull(rsStatement("Company"))
            If sClient = "" Then sClient = EmptyIfNull(rsStatement("Salutation"))
            sAddress = DesignAddress(rsStatement("Address1"), rsStatement("Address2"), rsStatement("Address3"), rsStatement("Address4"), rsStatement("Postcode"))
            sOut = Replace(sOut, "$$Client_ID$$", sClientID)
            sOut = Replace(sOut, "$$Client_Name$$", nbspIfEmpty(sClient))
            sOut = Replace(sOut, "$$Client_Address$$", sAddress)
            If Request.QueryString("date") <> "" Then
                sOut = Replace(sOut, "$$Statement_Date$$", Request.QueryString("date"))
            Else
                sOut = Replace(sOut, "$$Statement_Date$$", sDate)
            End If
            bFirst = False
        End If
        nDRTotal = Math.Round(ZeroIfNull(rsStatement("InvoicesPH")) + ZeroIfNull(rsStatement("InvoicesContract")) + ZeroIfNull(rsStatement("InvoicesFE")) + ZeroIfNull(rsStatement("InvoicesCMP")), 2)
        If nDRTotal = 0 Then
            nCRTotal = ZeroIfNull(rsStatement("Payments"))
            nPaymentsAlloc = -ZeroIfNull(rsStatement("CreditsAlloc"))
            nInvTotal = Math.Round(-nPaymentsAlloc - nCRTotal, 2)
        Else
            nCRTotal = -ZeroIfNull(rsStatement("Payments")) + ZeroIfNull(rsStatement("Adjustments")) + ZeroIfNull(rsStatement("Credits")) - ZeroIfNull(rsStatement("CreditsAlloc"))
            nPaymentsAlloc = 0
            Select Case rsStatement("Type")
                Case "TR", "CH", "CA", "CC"
                    nPaymentsAlloc = GetPaymentsAlloc(rsStatement("InvoiceNo"))
            End Select
            nInvTotal = Math.Round(ZeroIfNull(rsStatement("InvoicesPH")) + ZeroIfNull(rsStatement("InvoicesContract")) + ZeroIfNull(rsStatement("InvoicesFE")) + ZeroIfNull(rsStatement("InvoicesCMP")) - ZeroIfNull(rsStatement("Payments")) + ZeroIfNull(rsStatement("Adjustments")) + ZeroIfNull(rsStatement("Credits")) - ZeroIfNull(rsStatement("CreditsAlloc")) + nPaymentsAlloc, 2)
        End If
        '               
        If nInvTotal <> 0 Then
            iLines = iLines + 10
            sHTML = sHTML & "<tr><td class=""data"" align=""center"">" & FormatDate(rsStatement("InvoiceDate"), sDateFormat) & "</td>" & _
             "<td class=""data"">" & FormatRef(rsStatement("Type"), rsStatement("InvoiceNo")) & "</td>" & _
             "<td class=""data"" align=""right"">" & ShowValue(nDRTotal, rsStatement("Type"), "DR") & "</td>" & _
             "<td class=""data"" align=""right"">" & ShowValue(nCRTotal, "CR", "CR") & "</td>" & _
             "<td class=""data"" align=""right"">" & ShowValue(nInvTotal, rsStatement("Type"), "TOTAL") & "</td></tr>"
            '"<td class=""data"" align=""right"">" & ShowValue(nDRTotal + nCRTotal + nPaymentsAlloc, rsStatement("Type"), "TOTAL") & "</td></tr>"               

            dCompareDate = rsStatement("InvoiceDate")

            ' 12/11/13 changed statement ageing to days base for statements dated mid-month  MB
            If DateDiff("d", dCompareDate, CDate(sDate)) >= 90 Then
                n90Days = n90Days + nInvTotal
            ElseIf DateDiff("d", dCompareDate, CDate(sDate)) >= 60 Then
                n60Days = n60Days + nInvTotal
            ElseIf DateDiff("d", dCompareDate, CDate(sDate)) >= 30 Then
                n30Days = n30Days + nInvTotal
            Else
                nCurrent = nCurrent + nInvTotal
            End If
        End If
    Loop

    sOut = Replace(sOut, "$$Statement_Data$$", sHTML)
    sOut = Replace(sOut, "$$90Days_Amount$$", ShowBalance(n90Days))
    sOut = Replace(sOut, "$$60Days_Amount$$", ShowBalance(n60Days))
    sOut = Replace(sOut, "$$30Days_Amount$$", ShowBalance(n30Days))
    sOut = Replace(sOut, "$$Current_Amount$$", ShowBalance(nCurrent))
    sOut = Replace(sOut, "$$Total_Amount$$", ShowBalance(n90Days + n60Days + n30Days + nCurrent))
    rsStatement.Close() : rsStatement = Nothing

    If sSection <> "" Then
        ApplyStatementDetails = GetDocumentSection(sOut, "all") & GetDocumentSection(sOut, sSection)
    Else
        ApplyStatementDetails = sOut
    End If
End Function

1 个答案:

答案 0 :(得分:0)

此代码看起来更像vbscript而不是VB.Net。 VB.Net非常不同,使用VB.Net时从vbscript中学到的许多约定都没有用。

阅读方法,我在顶部看到了这一点:

Dim sSQL As String

不久之后紧随其后:

rsStatement = New SqlCommand(sSQL, cnStatemnt).ExecuteReader

但两者之间没有分配给sSQL的值。它正在执行一个空的SQL字符串。