Android Tutorial [B4X] B4XTable - Load data from SQL database

Discussion in 'Tutorials & Examples' started by Erel, Feb 10, 2019.

  1. Erel

    Erel Administrator Staff Member Licensed User

    B4XTable.SetData expects a List where each entry in the list is an array of objects with the data of a single row.

    The data can come from any source you like.


    Example of loading the data from a SQL database:
    B4XTable1.AddColumn("Customer Id", B4XTable1.COLUMN_TYPE_NUMBERS)
    "Name", B4XTable1.COLUMN_TYPE_TEXT)
    "Company", B4XTable1.COLUMN_TYPE_TEXT)
    "Address", B4XTable1.COLUMN_TYPE_TEXT)

    Dim Data As List
    Dim rs As ResultSet = sql.ExecQuery("SELECT CustomerId, FirstName, LastName, Company, Address FROM customers")
    Do While rs.NextRow
    Dim row(4As Object
    0) = rs.GetDouble("CustomerId")
    1) = rs.GetString("FirstName") & " " & rs.GetString("LastName")
    2) = rs.GetString("Company")
    'Some of the values are Null. We need to convert them to empty strings:
           If row(2) = Null Then row(2) = ""
    3) = rs.GetString("Address")
    Step #1: add the columns.
    Step #2: fill the Data list with the data coming from the SQL db.
    Step #3: call B4XTable.SetData.

    B4A project is attached.

    Database source:

    Attached Files:

    koaunglay, ilan, DroidLyon and 17 others like this.
  2. Omar Moreno

    Omar Moreno Member Licensed User


    The library is very good.
    You could show the code to load a column with SQLITE BLOB type values.

    Thank you.
  3. Erel

    Erel Administrator Staff Member Licensed User

  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