2014-09-02 149 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