Android Question [SOLVED] B4XTable ExecNonQuery2 Select

makis_best

Well-Known Member
Licensed User
Longtime 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.

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:
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
I want to do calculations based of user input.

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:

B4X:
    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)
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
This is what I do in the B4XTable1_DataUpdated sub
Nice example Jimmy: Could you have combined both transactions in one like this:
B4X:
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
 
Upvote 0

jimmyF

Active Member
Licensed User
Longtime User
Could you have combined both transactions in one like this:
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
 
Upvote 0
Top