B4J Question Error Setting Second B4XTable

Setlodi

Active Member
Hi Friends

I hope you can help with the ptoblem I'm facing. I have 2 tables which I have created:
Tables created:
    TABLE 1
    
Public Sub Create_Customer_Table
    Dim Customer_IDNo_Column As B4XTableColumn = tblCustomers.AddColumn("Customer ID No", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Customer_Name_Column As B4XTableColumn = tblCustomers.AddColumn("Customer Name", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Customer_Surname_Column As B4XTableColumn = tblCustomers.AddColumn("Customer Surame", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Customer_Phone_No_Column As B4XTableColumn = tblCustomers.AddColumn("Customer Telephone", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Customer_Area_Column As B4XTableColumn = tblCustomers.AddColumn("Customer Area", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Customer_Status As B4XTableColumn = tblCustomers.AddColumn("Customer Status", tblCustomers.COLUMN_TYPE_TEXT)

    Customer_IDNo_Column.width = 80dip
    Customer_Name_Column.width = 150dip
    Customer_Surname_Column.width = 150dip
    Customer_Phone_No_Column.width = 150dip
    Customer_Area_Column.width = 150dip
    Customer_Status.width = 150dip
    
    tblCustomers.LabelsFont = xui.CreateDefaultFont(11)
    tblCustomers.RowHeight = 30dip
    tblCustomers.MaximumRowsPerPage = 20
    tblCustomers.BuildLayoutsCache(tblCustomers.MaximumRowsPerPage)
    tblCustomers.HeaderFont = xui.CreateDefaultBoldFont(11)
    tblCustomers.HeadersHeight =25dip
End Sub

    
    TABLE 2
    
Public Sub Create_Customer_Detail_Table
    Dim Order_Product_Code_Column As B4XTableColumn = tblCustomers.AddColumn("Code", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Order_Barcode_Column As B4XTableColumn = tblCustomers.AddColumn("Barcode", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Order_Product_Name_Column As B4XTableColumn = tblCustomers.AddColumn("Name", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Order_Product_Cost_Column As B4XTableColumn = tblCustomers.AddColumn("Cost Price", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Order_Product_Price_Column As B4XTableColumn = tblCustomers.AddColumn("Selling Price", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Order_Product_Quantity_Column As B4XTableColumn = tblCustomers.AddColumn("Quantity", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Order_Category_Name_Column As B4XTableColumn = tblCustomers.AddColumn("Category", tblCustomers.COLUMN_TYPE_TEXT)
    Dim Order_Total_Item_Orders_Column As B4XTableColumn = tblCustomers.AddColumn("Total", tblCustomers.COLUMN_TYPE_TEXT)

    Order_Product_Code_Column.width = 60dip
    Order_Barcode_Column.width = 60dip
    Order_Product_Name_Column.width = 200dip
    Order_Product_Cost_Column.width = 60dip
    Order_Product_Price_Column.width = 60dip
    Order_Product_Quantity_Column.width = 60dip
    Order_Category_Name_Column.width = 150dip
    Order_Total_Item_Orders_Column.width = 100dip

    tblCustomers.LabelsFont = xui.CreateDefaultFont(11)
    tblCustomers.RowHeight = 30dip
    tblCustomers.MaximumRowsPerPage = 20
    tblCustomers.BuildLayoutsCache(tblCustomers.MaximumRowsPerPage)
    tblCustomers.HeaderFont = xui.CreateDefaultBoldFont(11)
    tblCustomers.HeadersHeight =25dip   
End Sub

I'm setting the first table form a SQLlite query:
Setting first table:
Create_Customer_Table
    Dim CustomerData As List
    CustomerData.Initialize
    Dim rs As ResultSet = Main.SQL.ExecQuery("SELECT * FROM Customer_Table")
    Do While rs.NextRow

        Dim Customer_IDNo As String = rs.GetString("Cust_ID_Number")
        Dim Customer_Name As String = rs.GetString("Cust_Name")
        Dim Customer_Surname As String = rs.GetString("Cust_Surname")
        Dim Customer_Phone As String = rs.GetString("Cust_Phone_No")
        Dim Customer_Area As String = rs.GetString("Cust_Area")
        Dim Customer_Status As String = rs.GetString("Cust_Status")

        CustomerData.Add(Array(Customer_IDNo, Customer_Name, Customer_Surname, Customer_Phone, Customer_Area, Customer_Status))

    Loop
    rs.Close
   
    Try
        tblCustomers.SetData(CustomerData)
    Catch
        Log("Failed to set data")
        Log(LastException)
    End Try

The first table is set successfully.
From here I click a row on the first table, get a string, query the second SQlite table then try to set the second table'
Setting the second table:
Private Sub tblCustomers_CellClicked (ColumnId As String, RowId As Long)
    
    pnlViewCustomerDetails.Visible = True
    Dim RowData As Map = tblCustomers.GetRow(RowId)
    Log("RowData = " & RowData)
    Dim CustomerIDNo As String = RowData.Get("Customer ID No")
    Log("^^^^^ CustomerIDNo = " & CustomerIDNo)
    
    Create_Customer_Detail_Table
    Dim CustomerOrderData As List
    CustomerOrderData.Initialize
    
    ' Getting total orders for customer
    Dim rs As ResultSet =Main.SQL.ExecQuery2("SELECT * FROM Orders_Table2 WHERE Order_Customer_ID = ?", Array As Object(CustomerIDNo))
    Do While rs.NextRow
'        Dim OrderDetailTotalAmt As String = rs.GetString("Order_Group_Total")

        Dim Order_Product_Code As String  =  rs.GetString("Order_Product_Code")
        Dim Order_Barcode As String  =  rs.GetString("Order_Barcode")
        Dim Order_Product_Name As String  =  rs.GetString("Order_Product_Name")
        Dim Order_Product_Cost As String  =  rs.GetString("Order_Product_Cost")
        Dim Order_Product_Price As String  =  rs.GetString("Order_Product_Price")
        Dim Order_Product_Quantity As String  =  rs.GetString("Order_Product_Quantity")
        Dim Order_Category_Name As String  =  rs.GetString("Order_Category_Name")
        Dim Order_Total_Item_Orders As String  =  rs.GetString("Order_Total_Item_Orders")
        
        Log("Order_Product_Code  = " & Order_Product_Code)
        Log("Order_Barcode  = " & Order_Barcode)
        Log("Order_Product_Name  = " & Order_Product_Name)
        Log("Order_Product_Cost  = " & Order_Product_Cost)
        Log("Order_Product_Price  = " & Order_Product_Price)
        Log("Order_Product_Quantity  = " & Order_Product_Quantity)
        Log("Order_Category_Name  = " & Order_Category_Name)
        Log("Order_Total_Item_Orders  = " & Order_Total_Item_Orders)
        Log("_____________________")

        CustomerOrderData.Add(Array(Order_Product_Code, Order_Barcode, Order_Product_Name, Order_Product_Cost, Order_Product_Price, Order_Product_Quantity, Order_Category_Name, Order_Total_Item_Orders))
Loop
    rs.Close
    
    Try
        tblCustomerDetails.SetData(CustomerOrderData)
        Sleep(5000)
    Catch
        Log("Failed to set data")
        Log(LastException)
    End Try
    
End Sub

The second table is not set and I get the following error:
B4X:
(SQLException) java.sql.SQLException: [SQLITE_ERROR] SQL error or missing database (near ")": syntax error)

I tried to set the table using after getting query results in rows

B4X:
tblCustomerDetails.SetData(row)
 

Setlodi

Active Member
It appears you're using tblCustomers instead of tblCustomerDetails in Sub Create_Customer_Detail_Table?
Walt61 you are so right!!! Happens sometimes when you copy and paste your code! I changed the code and now it works perfectly. Thank you very much!!!
 
Upvote 0
Top