B4J Question SQL check if record exists.

vdudukov

Member
Licensed User
Longtime User
Hi,

I don't know how to check database record in B4J, so if can somebody help please :)
Thanks!


Here is how I check in B4A:)



B4X:
txt= "SELECT code FROM contact WHERE name = '" & edit_name.text & "'"
    cursor1 = SQL1.ExecQuery(txt)
    If cursor1.RowCount>0 Then
    Return
    Else
 

vdudukov

Member
Licensed User
Longtime User
B4X:
Dim cursor1 As ResultSet = SQL1.ExecQuery2("SELECT code FROM contact WHERE name = ?", Array As String(edit_name.text))
Dim res As Boolean
If Cursor1.NextRow Then res = True
Cursor1.Close
Return res

Thank you.
This code works for me.


B4X:
 Dim cursor As ResultSet
            cursor = SQL1.ExecQuery("SELECT code FROM contacts WHERE name = '" & edit_name.text & "'")
            If cursor.NextRow Then
            txtLog3.Text = cursor.GetString("code")
            cursor.Close
            Else
            txtLog3.Text = "OK"
            cursor.Close
            End If
 
Upvote 0
Top