Android Question (ask) Build function from VB.Net to b4a

hugoyaw

Member
hi people, i want to ask how to translate code from VB like below

Code:
    Public Function GetSingleQuery(ByVal SqlCommand As String) As String
        GetSingleQuery = "0"

        For i = 2 To 0 Step -1
            Try
                BukaKoneksi()

                Dim command As MySqlCommand = New MySqlCommand(SqlCommand, cn)
                'command.CommandTimeout = 600
                Dim reader As MySqlDataReader = command.ExecuteReader
                While reader.Read
                    If Not IsDBNull(reader.GetValue(0)) Then
                        GetSingleQuery = reader.GetValue(0)
                    Else
                        GetSingleQuery = "0"
                    End If
                End While
                reader.Close()

                Exit For
            Catch ex As Exception
                If i = 0 Then
                    MsgBox(ex.Message)
                Else
                    Thread.Sleep(100)
                End If
            End Try
        Next

        Return GetSingleQuery
    End Function

with

B4X:
Dim req As DBRequestManager = CreateRequest
    Dim cmd As DBCommand = CreateCommand("operator_count", Array(UserName_edt.Text, Password_edt.Text))
    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)
               
        Dim nCount As Int
        For Each row() As Object In res.Rows
            nCount = row(res.Columns.Get("COUNT"))
        Next

        If nCount > 0 Then
           
            StartActivity(Menu)
        Else
            xui.MsgboxAsync("Username atau password salah !" , "Info")
        End If
    Else
        Log("ERROR: " & j.ErrorMessage)
    End If
    j.Release

to function in b4a
I want just input command name, parameter that return string
so i can use dynamically and the code is not too long.
thx before
 

MikeSW17

Active Member
Licensed User
Longtime User
Is this "BukaKoneksi()"?

B4X:
Public Sub BukaKoneksi()
 
If CONN.State = 1 Then CONN.Close ' jika koneksi masih terbuka makan akan ditutup
 
LokasiDB = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & App.Path & "\dbLatihan.mdb"
 
CONN.Open LokasiDB
 
Upvote 0

hugoyaw

Member
You actually have posted the answer for B4A. What is your question?
mr. @aeric my question is how to make the queries that I make easier to use.

below is an example of how I pull data into variables from the database via vb.net

B4X:
HargaJual.Text = GetQuery ("SELECT product.HARGA_JUAL FROM product")
 
Upvote 0
Top