2014-09-02 66 views
0

所以我檢索數據通過SQL及其聲明頁面。它有客戶,日期,交易,借記卡,信用卡和餘額列。現在談到一個信用而不是借方的交易時,它不會顯示。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 
+0

請格式化的問題。另外你爲什麼不使用的SP,而不是直接插入SQL – Seminda 2014-09-02 01:27:15

+0

@Seminda我包括上述 – user3566985 2014-09-02 01:53:28

+0

這個問題的一些安全漏洞,在這裏,如信任用戶輸入:'時間=替換(SOUT,「$$ Statement_Date $$」的Request.QueryString( 「date」))' – ErikE 2014-09-02 02:58:07

回答

0

這段代碼看起來更像是VBScript中比VB.Net。 VB.Net是非常不同的,從VBScript中學到的很多約定在使用VB.Net時不再有意義。

讀取的方法,我看到這個頂部:

Dim sSQL As String 

由這是繼後不久:

rsStatement = New SqlCommand(sSQL, cnStatemnt).ExecuteReader 

但無處之間是曾經分配給sSQL的值。它正在執行一個空的SQL字符串。

+0

我從帖子中刪除了SQL語句,因爲它很長,我不認爲它與SQL語句有任何關係。我定義了SQL罰款,它只是當一個帳戶的信用爲負時,它不會顯示在表上 – user3566985 2014-09-02 05:53:28