Android Question Using result set of b4xpages

Makumbi

Well-Known Member
Licensed User
how can i convert this code use results set

B4X:
Dim bitmaps As List = Array("images2.jpg","images2.jpg")
    'smiley = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
    cursor1 = Starter.SQL1.ExecQuery("SELECT anounce FROM anouncements")
            If cursor1.RowCount > 0 Then
                For i = 0 To cursor1.RowCount-1
                    cursor1.Position = i
            Dim Phoneg As String
            Phoneg =cursor1.Getstring("anounce")
            'Log(Phoneg)
            If Phoneg=Null Then
                Return
            End If
            Log(i)
          
            Dim content As String = Phoneg
            Log(content)
            CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")

                Next
            End If

this is what i was trying but has errors
B4X:
    Dim rs As ResultSet  = B4XPages.MainPage.SQL.ExecQuery("SELECT anounce FROM anouncements")
    Do While rs.NextRow
        Dim row(6) As Object
    If cursor1.RowCount > 0 Then
                For i = 0 To cursor1.RowCount-1
                    cursor1.Position = i
        row(0) = rs.GetString("anounce")
        Dim Phoneg As String
        Phoneg =rs.Getstring("anounce")
        data.Add(row)
        If row(0)=Null Then
            Return
        End If
       
        Dim content As String = Phoneg
        Log(content)
        CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")

    Loop
    rs.Close
 
Last edited:

Makumbi

Well-Known Member
Licensed User
how can i convert this code use results set

B4X:
Dim bitmaps As List = Array("images2.jpg","images2.jpg")
    'smiley = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
    cursor1 = Starter.SQL1.ExecQuery("SELECT anounce FROM anouncements")
            If cursor1.RowCount > 0 Then
                For i = 0 To cursor1.RowCount-1
                    cursor1.Position = i
            Dim Phoneg As String
            Phoneg =cursor1.Getstring("anounce")
            'Log(Phoneg)
            If Phoneg=Null Then
                Return
            End If
            Log(i)
        
            Dim content As String = Phoneg
            Log(content)
            CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")

                Next
            End If

this is what i was trying but has errors
B4X:
    Dim rs As ResultSet  = B4XPages.MainPage.SQL.ExecQuery("SELECT anounce FROM anouncements")
    Do While rs.NextRow
        Dim row(6) As Object
    If cursor1.RowCount > 0 Then
                For i = 0 To cursor1.RowCount-1
                    cursor1.Position = i
        row(0) = rs.GetString("anounce")
        Dim Phoneg As String
        Phoneg =rs.Getstring("anounce")
        data.Add(row)
        If row(0)=Null Then
            Return
        End If
     
        Dim content As String = Phoneg
        Log(content)
        CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")

    Loop
    rs.Close
Thanks Lucas but i just i wanted to convert this code to cross platform of b4xpages because iam to trying to write the code right
here
B4X:
Dim bitmaps As List = Array("images2.jpg","images2.jpg")
    'smiley = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
    cursor1 = Starter.SQL1.ExecQuery("SELECT anounce FROM anouncements")
            If cursor1.RowCount > 0 Then
                For i = 0 To cursor1.RowCount-1
                    cursor1.Position = i
            Dim Phoneg As String
            Phoneg =cursor1.Getstring("anounce")
            'Log(Phoneg)
            If Phoneg=Null Then
                Return
            End If
            Log(i)
         
            Dim content As String = Phoneg
            Log(content)
            CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")

                Next
            End If
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try this code:
B4X:
    Dim bitmaps As List = Array("images2.jpg","images2.jpg")
    'smiley = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
    Private rs As ResultSet
    rs = SQL1.ExecQuery("SELECT anounce FROM anouncements")
    Private i = - 1 As Int
    Do While rs.NextRow
        i = i + 1
        Dim Phoneg As String
        Phoneg = rs.Getstring("anounce")
        'Log(Phoneg)
        If Phoneg=Null Then
            Return
        End If
       
        Dim content As String = Phoneg
        Log(content)
        CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")
    Loop
    rs.Close

You need to move the SQL initialization code from the Starter module to the B4XMainPage module.

You may have a look at these B4X Booklets.
B4X SQLite Database
B4XPages Cross-plarform projects
 
Last edited:
Upvote 0

Makumbi

Well-Known Member
Licensed User
Try this code:
B4X:
    Dim bitmaps As List = Array("images2.jpg","images2.jpg")
    'smiley = LoadBitmapResize(File.DirAssets, "smiley.png", 24dip, 24dip, False)
    Private rs As ResultSet
    rs = SQL1.ExecQuery("SELECT anounce FROM anouncements")
    Private i = - 1 As Int
    Do While rs.NextRow
        i = i + 1
        Dim Phoneg As String
        Phoneg = rs.Getstring("anounce")
        'Log(Phoneg)
        If Phoneg=Null Then
            Return
        End If
       
        Dim content As String = Phoneg
        Log(content)
        CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")
    Loop

You need to move the SQL initialization code from the Starter module to the B4XMainPage module.

You may have a look at these B4X Booklets.
B4X SQLite Database
B4XPages Cross-plarform projects

thank you for the great help but after trying out your code i am getting error Next is missing yet the loop command is there
B4X:
Root = Root1
    Root.LoadLayout("noticeboard")
    B4XPages.SetTitle(Me, "Notice Board") 'Page title
    Dim mi As B4AMenuItem = B4XPages.AddMenuItem(Me, "refresh")
    mi.AddToBar = True
    mi.Bitmap = xui.LoadBitmapResize(File.DirAssets, "ic_cached_white_24dp.png", 32dip, 32dip, True)
    Dim mit As B4AMenuItem = B4XPages.AddMenuItem(Me, "Done")
    mit.AddToBar = True
    mit.Bitmap = xui.LoadBitmapResize(File.DirAssets, "ic_done_white_24dp.png", 32dip, 32dip, True)

    Dim rs As ResultSet  = B4XPages.MainPage.SQL.ExecQuery("SELECT anounce FROM anouncements")
    
    Do While rs.NextRow
    Dim row(6) As Object
    If cursor1.RowCount > 0 Then
        For i = 0 To cursor1.RowCount-1
        cursor1.Position = i
        row(0) = rs.GetString("anounce")
        Dim Phoneg As String
        Phoneg =rs.Getstring("anounce")
        data.Add(row)
            If row(0)=Null Then
            Return
        End If
    
    Dim content As String = Phoneg
    Log(content)
        CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")
        
        
    rs.Close
    Loop
    End If
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
For i = 0 To cursor1.RowCount-1
cursor1.Position = i
Your code is wrong. Don't use cursor. Replace the 2 lines of code with:
B4X:
i = i + 1
as written by klaus.

You should also close the resultset after the Loop keyword.
B4X:
[QUOTE="Makumbi, post: 875787, member: 112506"]
rs.Close
Loop
[/QUOTE]

B4X:
    Dim i As Int
    Dim row(6) As Object
    Private rs As ResultSet
    rs = SQL1.ExecQuery("SELECT anounce FROM anouncements")
    Do While rs.NextRow
        i = i + 1
        row(0) = rs.GetString("anounce")
        Dim Phoneg As String
        Phoneg = rs.Getstring("anounce")
        'Log(Phoneg)
        If Phoneg=Null Then
            Return
        End If
     
        Dim content As String = Phoneg
        Log(content)
        CLV1.Add(CreateItem(CLV1.AsView.Width, $"Anouncement #${i}"$, bitmaps.Get(0), content), "")
    Loop
    rs.Close
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
You have NOT used the code I suggested you !
You should replace all the code between Dim rs As ResultSet and rs.Close by the code in post #4 beginning with rs = SQL1.ExecQuery("SELECT anounce FROM anouncements").
 
Upvote 0
Top