hi people, i want to ask how to translate code from VB like below
with
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
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