Android Question Need help connecting to MSSQL

apty

Active Member
Licensed User
Longtime User
I have looked at the tutorial for connecting android to ms sql server where there are two options:
1. Pre-set the possible queries in the ASP script and then choose one of the queries by setting a parameter in the Http request.
2. Pass the query as-is to the database.
(https://www.b4x.com/android/forum/threads/connect-android-to-ms-sql-server-tutorial.13166/)

Kindly if possible assist me with the 1st example. I would very much appreciate if I get an example where the queries are specified in the ASP script.
 

apty

Active Member
Licensed User
Longtime User
Hi Erel,
I have checked RDC but it seems that it needs a VPS server. I am using a normal web hosting server e.g. mochahost.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
you could use something like

B4X:
op=request("op")
select case op
case "":mysql="select * from users"
case "getuser":mysql="select username,useremail from users where userid="&request("id")
case "deluser":mysql="delete from users where userid="&request("id")
end select

sql.CommandText=mysql
set myrs=sql.Execute

sql syntax depends on the driver tho so it might be different at your end.
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
I have tried RDC. I tried the code below for displaying a field in Listview from database but i just get a blank screen. Kindly assist:
B4X:
Sub JobDone(Job As HttpJob)
    If Job.Success = False Then
        Log("Error: " & Job.ErrorMessage)
    Else
        If Job.JobName = "DBRequest" Then
            Dim result As DBResult = reqManager.HandleJob(Job)
            'reqManager.PrintTable(result)
            For Each records() As Object In result.Rows
                        ' Now Load info
                        Dim bookid As String
                        bookid = records(result.Columns.Get("name"))


ListView1.AddSingleLine(bookid)
                    Next
        End If
    End If
    Job.Release
End Sub
 
Upvote 0
Top