Android Question How do I display data from the database in a message box

luthfiagata

New Member
I want to display data in a text box by retrieving data from the database


MsgboxAsync:
Private Sub boxmesage_Click
    mdlkoneksi.koneksi
    mdlkoneksi.rs = mdlkoneksi.mh.Query("SELECT * FROM jadwalkerja WHERE idkaryawan =  '" & Main.idne & "' ")
    For i = 0 To mdlkoneksi.rs.RowCount - 1
        
        mdlkoneksi.rs.Position = i
        Dim now As Long
        Dim HARI, BULAN, TAHUN As String
        DateTime.TimeFormat = "dd-MM-yyyy"
        HARI  = DateTime.GetDayOfMonth(DateTime.Now)
        BULAN = DateTime.GetMonth(DateTime.Now)
        TAHUN = DateTime.GetYear(DateTime.Now)
    Next
    
    mdlkoneksi.rs = mdlkoneksi.mh.Query("SELECT * FROM jadwalkerja WHERE idkaryawan ='" & Main.idne & "' AND tanggaljadwal='" & TAHUN & ":" & BULAN & ":" & HARI & "' ")
    
    MsgboxAsync(mdlkoneksi.rs.GetString2("tanggaljadwal") & "         Kode Jadwal : " & mdlkoneksi.rs.GetString2("kodejadwal")  , " Info Jadwal Kerja")
    
End Sub
 

aeric

Expert
Licensed User
Longtime User
rs.GetString2
There are some mistakes in your code.
If you know the column name, use rs.GetString("tanggaljadwal")

Please also use parameterized query.

B4X:
Private Sub boxmesage_Click
    DateTime.DateFormat = "yyyy:MM:dd"
    Dim Today As String = DateTime.Date(DateTime.Now)
    Log(Today)
    
    Dim found As Boolean
    Dim tanggaljadwal As String
    Dim kodejadwal As String
    
    Dim stmt As String = "SELECT * FROM jadwalkerja WHERE idkaryawan = ? AND tanggaljadwal = ?"
    Dim rs As ResultSet = SQL.ExecQuery2(stmt, Array As String(Main.idne, Today))
    Do While rs.NextRow
        found = True
        tanggaljadwal = rs.GetString("tanggaljadwal")
        kodejadwal = rs.GetString("kodejadwal")
    Loop
    rs.Close
    
    If found Then
        xui.MsgboxAsync(tanggaljadwal & "         Kode Jadwal : " & kodejadwal, "Info Jadwal Kerja")
    Else
        Log("Not found")
    End If
End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…