B4J Question Can we convert sample asp.net script webserver to B4J ?

Gnappo jr

Active Member
Licensed User
Longtime User
In Connect Android to MS SQL Server Tutorial:
https://www.b4x.com/android/forum/threads/connect-android-to-ms-sql-server-tutorial.13166/
There is a very effective asp.net script, i would like to do the same thing in b4j, can i get help? Also for this part of ASP code:

while (rdr.Read())
{
Dictionary<string, object> d = new Dictionary<string, object>(rdr.FieldCount);for (int i =0;i < rdr.FieldCount;i++)
{
d[rdr.GetName(i)] = rdr.GetValue(i);}
list.Add(d);
}
JavaScriptSerializer j = new JavaScriptSerializer();
Response.Write(j.Serialize(list.ToArray()));

}
Thanks to anyone
 

Gnappo jr

Active Member
Licensed User
Longtime User
A much more efficient and better implementation is available in jRDC2.
Thanks Erel, I will study jRDC2.
For study purposes and to prove that the ASP server in the example can be done in B4J, you should convert this
aspnet server code
...
JavaScriptSerializer j = new JavaScriptSerializer();
Response.Write(j.Serialize(list.ToArray()));

...

in B4J code.
I'm stranded here: (B4J server)
Sub Handle(req As ServletRequest, resp As ServletResponse)
mreq = req
mresp = resp
Dim miasql As String, ser As B4XSerializator, lista As List
miasql=mreq.GetParameter("query")
lista=ExecuteMemoryTable(Main.sql1, miasql , Null, 0 )

resp.ContentType ="text/html" '????????????
resp.Write( ser.ConvertObjectToBytes(lista)) '???????????????
' What is the correct code?

End Sub

This is the B4A client code that works well with asp server
Sub JobDone (Job As HttpJob)
If Job.Success Then
Dim parser As JSONParser
Dim response As String = Job.GetString
parser.Initialize(response)
Dim rows As List
rows = parser.NextArray
Select Case Job.JobName
Case "Job0"
'work with result
'rows is a List. Each item is a Map with the columns names as keys and the db values as the values.
For i = 0 To rows.Size - 1
Log("Rows #" & i)
Dim m As Map
m = rows.Get(i)
TotPersone.Text=m.Get("TotPersone")
Next

.....
....
 
Upvote 0
Top