Android Question CursorIndexOutofBoundsException

ProjectGroup19

Active Member
Licensed User
Try
Dim RowId As Long = GetRowId(Sender)
Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
Connection.CU.Position=0
Dim name As String=Connection.CU.GetString("USERNAME")
If name= "ADMIN" Then
Msgbox("You can not delete this account.","ADMIN ACCOUNT")
Return
Else
Dim Item As Map = B4XTable1.GetRow(RowId)
Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)
Wait For (sf) Msgbox_Result (Result As Int)

If Result = xui.DialogResponse_Positive Then
B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))
Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))
Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))
B4XTable1.ClearDataView 'update the table
End If
End If


Catch
Msgbox(LastException.Message, "Error")
End Try
 

walterf25

Expert
Licensed User
Longtime User
Try
Dim RowId As Long = GetRowId(Sender)
Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
Connection.CU.Position=0
Dim name As String=Connection.CU.GetString("USERNAME")
If name= "ADMIN" Then
Msgbox("You can not delete this account.","ADMIN ACCOUNT")
Return
Else
Dim Item As Map = B4XTable1.GetRow(RowId)
Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)
Wait For (sf) Msgbox_Result (Result As Int)

If Result = xui.DialogResponse_Positive Then
B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))
Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))
Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))
B4XTable1.ClearDataView 'update the table
End If
End If


Catch
Msgbox(LastException.Message, "Error")
End Try
At which line in the code are you getting that error?, you need to be more specific when asking for help.

Walter
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)

        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )

        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)

  

            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If

        End If

    



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)

        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )

        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If

        End If

  



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
The If statement works fine because it returns a row value from the cursor(row count is 1) but the else statement does not work because the cursor does not return any row value(row count is 0).
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)

        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )

        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)

 

            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If

        End If

   



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
That means that there's nothing being returned from the Query.

Do something like this:
B4X:
Try

        Dim RowId As Long = GetRowId(Sender)
        Log("RowId: " + Rowid)
        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
        if Connectioin.CU.Rowcount > 0 then
        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)

 

            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
        End If

    



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
The If statement works fine because it returns a row value from the cursor(row count is 1) but the else statement does not work because the cursor does not return any row value(row count is 0).
Then that means there is no data in your Table with that specific RowId number or there's no data at all to be returned.

Walter
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
Then that means there is no data in your Table with that specific RowId number or there's no data at all to be returned.

Walter
There is data because it verifies the the If statement correctly but it seems after it tests the if statement, then the cursor is consumed or destroyed so it returns no value for it to test the else statement. Please, how do i make the cursor test both the if and else statements.
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
That means that there's nothing being returned from the Query.

Do something like this:
B4X:
Try

        Dim RowId As Long = GetRowId(Sender)
        Log("RowId: " + Rowid)
        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
        if Connectioin.CU.Rowcount > 0 then
        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
        End If

   



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
I tried this but it didn't work
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Ok, in order for anyone to help you, you need to be more specific, when you say "it doesn't work" that could mean a number of things, you need to specify exactly what doesn't work, what error do you get etc...

In the Else Statement you have this:

B4X:
Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
At which line in that code do you see the problem, does the MsgBox2Async pops up, if you log the Item object, do you see any data in that map?

Walter
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
Ok, in order for anyone to help you, you need to be more specific, when you say "it doesn't work" that could mean a number of things, you need to specify exactly what doesn't work, what error do you get etc...

In the Else Statement you have this:

B4X:
Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
At which line in that code do you see the problem, does the MsgBox2Async pops up, if you log the Item object, do you see any data in that map?

Walter

Ok, in order for anyone to help you, you need to be more specific, when you say "it doesn't work" that could mean a number of things, you need to specify exactly what doesn't work, what error do you get etc...

In the Else Statement you have this:

B4X:
Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
At which line in that code do you see the problem, does the MsgBox2Async pops up, if you log the Item object, do you see any data in that map?

Walter
CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)

        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )

        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)

  

            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If

        End If

    



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
i meant, after they
That means that there's nothing being returned from the Query.

Do something like this:
B4X:
Try

        Dim RowId As Long = GetRowId(Sender)
        Log("RowId: " + Rowid)
        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
        if Connectioin.CU.Rowcount > 0 then
        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
        End If

   



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
i meant, after trying your code, the if executes fine but the else does not execute at all, the log shows the RowId value according to its row in the table.
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
Try

Dim RowId As Long = GetRowId(Sender)
Log("RowId: " + Rowid)
Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
if Connectioin.CU.Rowcount > 0 then
Connection.CU.Position=0

Dim name As String=Connection.CU.GetString("USERNAME")

If name= "ADMIN" Then

Msgbox("You can not delete this account.","ADMIN ACCOUNT")

Return

Else

Dim Item As Map = B4XTable1.GetRow(RowId)

Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

Wait For (sf) Msgbox_Result (Result As Int)



If Result = xui.DialogResponse_Positive Then

B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

B4XTable1.ClearDataView 'update the table

End If
End If
End If





Catch

Msgbox(LastException.Message, "Error")

End Try

CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)
        Log("RowId: " + Rowid)
        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
        if Connectioin.CU.Rowcount > 0 then
        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)

 

            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
        End If

    



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
i meant, after trying your code, the if Highlighted, executes fine but the else highlighted does not execute at all, the log shows the RowId value according to its row in the table.
[/QUOTE]
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)

        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )

        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)

 

            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If

        End If

   



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
i meant, after they

i meant, after trying your code, the if executes fine but the else does not execute at all, the log shows the RowId value according to its row in the table.
Ok, again be more specific, The code I gave has 3 IF Statements in that code, which one executes fine? LOL, the first one checks if the rowcount is greater than 0, if the query returns more than 0 records then it moves onto the next IF Statement and so on, if the rowcount is 0 then it is obvious that the Else statement will not be executed as there are no records.

Walter
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Try

Dim RowId As Long = GetRowId(Sender)
Log("RowId: " + Rowid)
Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
if Connectioin.CU.Rowcount > 0 then
Connection.CU.Position=0

Dim name As String=Connection.CU.GetString("USERNAME")

If name= "ADMIN" Then

Msgbox("You can not delete this account.","ADMIN ACCOUNT")

Return

Else

Dim Item As Map = B4XTable1.GetRow(RowId)

Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

Wait For (sf) Msgbox_Result (Result As Int)



If Result = xui.DialogResponse_Positive Then

B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

B4XTable1.ClearDataView 'update the table

End If
End If
End If





Catch

Msgbox(LastException.Message, "Error")

End Try

CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)
        Log("RowId: " + Rowid)
        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )
        if Connectioin.CU.Rowcount > 0 then
        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If
        End If
        End If

   



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
i meant, after trying your code, the if Highlighted, executes fine but the else highlighted does not execute at all, the log shows the RowId value according to its row in the table.
[/QUOTE]
Ok in the
B4X:
 If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else
Does the MsgBox code get executed? does the MsgBox pop up?

Walter
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
Ok in the
B4X:
 If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else
Does the MsgBox code get executed? does the MsgBox pop up?

Walter
[/QUOTE]

Yes please, it does
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Ok in the
B4X:
 If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else
Does the MsgBox code get executed? does the MsgBox pop up?

Walter

Yes please, it does
[/QUOTE]
Ok, in that case it makes sense that the ELSE statement does not get executed, when you have If Else Statements, only one of the statements will be executed. I think it would be better for you to start with the Basic Tutorials so you can better understand what's going on.

Walter
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
Yes please, it does
Ok, in that case it makes sense that the ELSE statement does not get executed, when you have If Else Statements, only one of the statements will be executed. I think it would be better for you to start with the Basic Tutorials so you can better understand what's going on.

Walter
[/QUOTE]
I know only One will execute but it has to check the If condition if its false then it executes the else condition but its the cursor that I'm finding it difficult to do. How do i write this as a code "If name is Admin do this, else do that.
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Ok, in that case it makes sense that the ELSE statement does not get executed, when you have If Else Statements, only one of the statements will be executed. I think it would be better for you to start with the Basic Tutorials so you can better understand what's going on.

Walter
I know only One will execute but it has to check the If condition if its false then it executes the else condition but its the cursor that I'm finding it difficult to do. How do i write this as a code "If name is Admin do this, else do that.
[/QUOTE]
Ok, in that If Statement, when it checks if Name = "ADMIN" Then, if this is true it will execute this part, if is False it will go onto the Else Statement, but I don't see any cursor code after the Else Statement.

Walter
 
Upvote 0

ProjectGroup19

Active Member
Licensed User
CursorIndexOutOfBoundsException:
Try

        Dim RowId As Long = GetRowId(Sender)

        Connection.CU=Connection.DB.ExecQuery2("SELECT USERNAME FROM ACCOUNT WHERE rowid=? ",Array As String(RowId) )

        Connection.CU.Position=0

        Dim name As String=Connection.CU.GetString("USERNAME")

        If name= "ADMIN" Then

            Msgbox("You can not delete this account.","ADMIN ACCOUNT")

            Return

        Else

            Dim Item As Map = B4XTable1.GetRow(RowId)

            Dim sf As Object = xui.Msgbox2Async($"Delete Account: ${Item.Get("USERNAME")}?"$, "", "Yes", "", "No", Null)

            Wait For (sf) Msgbox_Result (Result As Int)



            If Result = xui.DialogResponse_Positive Then

                B4XTable1.sql1.ExecNonQuery2("DELETE FROM data WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM ACCOUNT WHERE rowid = ?", Array(RowId))

                Connection.DB.ExecNonQuery2("DELETE FROM USER WHERE rowid = ?", Array(RowId))

                B4XTable1.ClearDataView 'update the table

            End If

        End If

 



    Catch

        Msgbox(LastException.Message, "Error")

    End Try
log
Error occurred on line: 9 (EditableTable)
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
 
Last edited:
Upvote 0
Top