At which line in the code are you getting that error?, you need to be more specific when asking for help.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
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).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.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
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
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.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).
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.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
I tried this but it didn't workThat 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
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
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:
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?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
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:
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?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
Walter
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 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.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
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
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.i meant, after theyCursorIndexOutOfBoundsException: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 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.
[/QUOTE]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.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
If name= "ADMIN" Then
Msgbox("You can not delete this account.","ADMIN ACCOUNT")
Return
Else
If name= "ADMIN" Then
Msgbox("You can not delete this account.","ADMIN ACCOUNT")
Return
Else
Ok in the
Does the MsgBox code get executed? does the MsgBox pop up?B4X:If name= "ADMIN" Then Msgbox("You can not delete this account.","ADMIN ACCOUNT") Return Else
Walter
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.Yes please, it does
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.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
logCursorIndexOutOfBoundsException: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
Someone should kindly help me outlog
Error occurred on line: 9 (EditableTable)
android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?