Android Question [SOLVED] B4XTable ExecNonQuery2 Select

Discussion in 'Android Questions' started by makis_best, May 23, 2019.

  1. makis_best

    makis_best Active Member Licensed User

  2. Mahares

    Mahares Well Known Member Licensed User

    DonManfred and mangojack like this.
  3. makis_best

    makis_best Active Member Licensed User

  4. Erel

    Erel Administrator Staff Member Licensed User

    What do you want to do with the result of the select query? If you want to show it in the table then call Table.CreateDataView instead.
     
  5. makis_best

    makis_best Active Member Licensed User

    I want to do calculations based of user input.
    I Can't do it?
    I need to careful for something?
    If I want to specify a column name at Select script I use column ID?
     
    Last edited: May 27, 2019
  6. jimmyF

    jimmyF Active Member Licensed User

    This is how I do it:

    I have two columns, "OrderTotal" and "Tips"
    I placed two Labels, lblTips and lblOrders, on the form.
    (Look in your B4XTable Example in the ShowDialog sub for a hint)

    This is what I do in the B4XTable1_DataUpdated sub:

    Code:
    Dim rs As ResultSet = B4XTable1.sql1.ExecQuery("Select SUM(c7) From Data")
        
    If rs.NextRow Then
            
    If rs.GetString(rs.GetColumnName(0)) <> Null Then
                totalOrders = rs.GetString(rs.GetColumnName(
    0))
            
    Else
                
    Return
            
    End If
        
            
    Dim rs As ResultSet = B4XTable1.sql1.ExecQuery("Select SUM(c8) From Data")
            
    If rs.NextRow Then
                totalTips = rs.GetString(rs.GetColumnName(
    0))
            
    End If
        
    End If

       lblTips.Text = 
    "Tips: $" & NumberFormat(totalTips,1,2)
       lblOrders.Text = 
    "Orders: $" & NumberFormat(totalOrders,1,2)
     
  7. makis_best

    makis_best Active Member Licensed User

    @jimmyF Nice example....

    Thank you
     
    jimmyF likes this.
  8. Mahares

    Mahares Well Known Member Licensed User

    Nice example Jimmy: Could you have combined both transactions in one like this:
    Code:
    Dim rs As ResultSet = B4XTable1.sql1.ExecQuery("Select SUM(c7) as SC7, SUM(c8) as SC8 From Data")
       
    If rs.NextRow Then
                lblTips.Text = 
    "Tips: $" & NumberFormat(rs.GetDouble("SC7"),1,2)
                lblOrders.Text = 
    "Tips: $" & NumberFormat(rs.GetDouble("SC8"),1,2)
        
    End If
     
    jimmyF likes this.
  9. jimmyF

    jimmyF Active Member Licensed User

    Yes, I could have if I wasn't so lazy. ;)
    I added the second transaction a few days later and couldn't be bothered to optimize it at the time. App is still in development.
    Good point, though! :D
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice