Android Question How to operate the database after JRDC2 connection

Status
Not open for further replies.

K_Kai

Member
Hi:
I followed the tutorial to learn this post,(MSSQL)
And it succeeded,thanks a lot

But The result is output in log,I don’t know how to display it to the app
if i have db like this,(id is incremented)



if My app:


read, Update,delete,addnew with id
How to divide the above into multiple buttons
Please teach me again and I will study further
thanks again
 

Attachments

  • 2.RemoteDatabaseConnector.zip
    186.5 KB · Views: 142
  • config.properties.zip
    716 bytes · Views: 145

aeric

Expert
Licensed User
Longtime User
The result is output in log,I don’t know how to display it to the app
Use the new JRDC2 as told by Erel then change the GetAnimal sub to something like this:
B4X:
Sub GetAnimal(id As Int)
    Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("select_app", Array(id))
    Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone (j As HttpJob)
    If j.Success Then
        req.HandleJobAsync(j, "req")
        Wait For (req) req_Result(res As DBResult)
        'For Each row() As Object In res.Rows
        '    EditText2.Text = row(res.Columns.Get("name"))          
        '    EditText3.Text = row(res.Columns.Get("kg"))
        'Next
        Dim row() As Object = res.Rows.Get(0)
        EditText2.Text = row(res.Columns.Get("name"))
        EditText3.Text = row(res.Columns.Get("kg"))
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release
End Sub
 
Last edited:
Upvote 0

K_Kai

Member
 
Upvote 0

K_Kai

Member
HandleJobAsync is inside DBRequestManager.bas
Are you using JRDC2 from [B4X] jRDC2 - B4J implementation of RDC (Remote Database Connector) ?
Yes,I make a mistake ,I relearned “ JRDC2-B4J”,
and now,It's successful ,Thank you very very much!

But there is no update process in the example ,I tried to write it by myself,But i'm failed again

in config.properties:
B4X:
sql.update_app=update app set kg=? where id=?
B4X:
Sub UpdateRecord(kg As String,id As Int)
    Dim cmd As DBCommand = CreateCommand("update_app", Array(kg,id))
    Dim j As HttpJob = CreateRequest.ExecuteBatch(Array(cmd), Null)
    Wait For(j) JobDone(j As HttpJob)
    If j.Success Then
        Log("Inserted successfully!")
    Else
        Log("error:" & j.ErrorMessage)
    End If
    j.Release
End Sub
Sub Button2_Click
    UpdateRecord(EditText3.Text,EditText1.Text )
End Sub
 
Upvote 0
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…