hi,

below is my code. i want to get grand total based on boothID but i seems my code does not functioning. I still get same GRANDTOTAL even i have different BoothId in the sql. How do i do that. Do i need to add something in my code. PLEASE GUIDE ME!!!

Public Function CreditBalance() As Double
        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim icount As Integer
        Dim strSQL As String = ""
        Dim connStr As String
        Dim dr As SqlDataReader

        myConnection = GetConnect("REMOTE")
        myConnection.Open()

  
        strSQL = "SELECT TOP 1 [GrandTotal],[BoothID] FROM RetailerBalance ORDER BY TransactionDate DESC"

         myCommand = New SqlCommand(strSQL, myConnection)
        dr = myCommand.ExecuteReader

        While dr.Read
            If Not dr.IsDBNull(0) Then
                CreditBalance = dr(0)
            End If
        End While
     
     myConnection.Close()
    End Function

If I am understanding correctly, I think that what you need is a where clause. Change your select statement to this:

SELECT TOP 1 [GrandTotal],[BoothID] 
FROM RetailerBalance 
WHERE [BoothID] = boothID
ORDER BY TransactionDate DESC

You will need to pass the booth id to this function like:

Public Function CreditBalance(byval boothID as integer) As Double

hi,

below is my code. i want to get grand total based on boothID but i seems my code does not functioning. I still get same GRANDTOTAL even i have different BoothId in the sql. How do i do that. Do i need to add something in my code. PLEASE GUIDE ME!!!

Public Function CreditBalance() As Double
        Dim myConnection As SqlConnection
        Dim myCommand As SqlCommand
        Dim icount As Integer
        Dim strSQL As String = ""
        Dim connStr As String
        Dim dr As SqlDataReader

        myConnection = GetConnect("REMOTE")
        myConnection.Open()

  
        strSQL = "SELECT TOP 1 [GrandTotal],[BoothID] FROM RetailerBalance ORDER BY TransactionDate DESC"

         myCommand = New SqlCommand(strSQL, myConnection)
        dr = myCommand.ExecuteReader

        While dr.Read
            If Not dr.IsDBNull(0) Then
                CreditBalance = dr(0)
            End If
        End While
     
     myConnection.Close()
    End Function

hi,

thank you its working now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.