Android Question RDC catch NULL record returned

Declan

Well-Known Member
Licensed User
Longtime User
I am using the following code to read data from a RDC request.
All works great, but I need to "catch" the NULL record field and action as per comments in below code:
B4X:
         If result.Tag = "check_ads" Then 'query tag
                     ProgressDialogHide
                     For Each records() As Object In result.Rows
                        
'******** I NEED TO CATCH NULL "id" RECORD HERE   
' IF "id" RECORD IS NULL THEN EXIT ACTIVITY
' IF "id" RECORD NOT NULL CONTINUE

                        Dim AdID As String = records(result.Columns.Get("id"))
                        Dim AdType As String = records(result.Columns.Get("option"))
 

Declan

Well-Known Member
Licensed User
Longtime User
Nope, that does not work:

B4X:
       If result.Tag = "check_ads" Then 'query tag
                    ProgressDialogHide
                            For Each records() As Object In result.Rows
                                Dim id As Object = records(result.Columns.Get("id"))
                               
                                If id = Null Then
                                    Activity.Finish
                                    StartActivity(Menu)
                                Else
                                 Dim AdID As String = id

                                    Dim AdID As String = records(result.Columns.Get("id"))
                                    Dim AdType As String = records(result.Columns.Get("option"))
                                           If AdType = 1 Then
                                            Log("We got Ad Option: " & AdType)
                                            Activity.LoadLayout("Ad1.bal")
                                            lblAdd1AdID.Text = AdID
                                            Dim Buffer() As Byte
                                            Buffer = records(result.Columns.Get("opt1img1"))
                                            Dim InputStream1 As InputStream
                                            InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
                                            Dim Bitmap1 As Bitmap
                                            Bitmap1.Initialize2(InputStream1)
                                            InputStream1.Close
                                            img1PnlAdd1.SetBackgroundImage(Bitmap1)
                                            vvv.Visible = False
                                        End If
                                End If
                              Next
                End If
    End If
End If
    Job.Release

it jumps from:
B4X:
For Each records() As Object In result.Rows
To:
B4X:
Job.Release

It seems not to see the NULL records
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
I sorted it out with the following, but seems cumbersome:
B4X:
        If result.Tag = "check_ads" Then
                    Dim ListOfMaps As List
                    ListOfMaps.Initialize
                        For Each row() As Object In result.Rows
                            ListOfMaps.Add(CreateMap("ID": row(0), "Option": row(1)))
                        Next
                    If ListOfMaps.Size < 1 Then
                        Activity.Finish
                        StartActivity(Menu)
                    End If
                   
                    If ListOfMaps.Size > 0 Then
                        For Each records() As Object In result.Rows
                            Dim AdID As String = records(result.Columns.Get("id"))
                            Dim AdType As String = records(result.Columns.Get("option"))
                           
                                If AdType = 1 Then
                                    Log("We got Ad Option: " & AdType)
                                    Activity.LoadLayout("Ad1.bal")
                                    lblAdd1AdID.Text = AdID
                                    'Bitmap Loading
                                    Dim Buffer() As Byte
                                    Buffer = records(result.Columns.Get("opt1img1"))
                                    Dim InputStream1 As InputStream
                                    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
                                    Dim Bitmap1 As Bitmap
                                    Bitmap1.Initialize2(InputStream1)
                                    InputStream1.Close
                                    img1PnlAdd1.SetBackgroundImage(Bitmap1)
                                    vvv.Visible = False
                                End If
                               
                        Next
                    End If
                End If
 
Upvote 0
Top