Android Question Data Exist in the database

vinzpogi

Member
I have a problem with my code here. In my database

idnumber | firstname | middlename | lastname | gender | username | password | usertype
1001 qwe qwe qwe Male admin admin Admin
1002 abc abc abc Male user user User

When i try to register that data again, the app force closes. But i have an If statement saying it will show a toastmessage if it exist already. Is there a missing code here or is there something wrong with my query?
 

Attachments

  • d.PNG
    33.8 KB · Views: 192

Lahksman

Active Member
Licensed User
Longtime User
In your select query you are using every field for comparison. You should only check on idnumber (I suppose this is a unique field).
B4X:
Sub RegisterEntry
    Private Query As String
    Private cursor1 As Cursor
   
    Query = "SELECT * FROM adminclient WHERE idnumber = ?"
    cursor1 = sql1.ExecQuery2(Query, Array As String(REGid.text))
   
    If cursor1.RowCount > 0 Then
        ....


If you want to compare other fields aswell you could combine several fields, for instance:
B4X:
Sub RegisterEntry
    Private Query As String
    Private cursor1 As Cursor
   
    Query = "SELECT * FROM adminclient WHERE (idnumber = ?) OR (firstname = ? AND middlename = ? AND lastname = ?)"
    cursor1 = sql1.ExecQuery2(Query, Array As String(REGid.text, REGfirst.text, REGmid.text, REGlast.text))
   
    If cursor1.RowCount > 0 Then
        ....
You are now checking on ID or combination of first, middle and lastname.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…