I have a development where i made a Com dll to communicate with Centura SQLBase:
COM DLL Code
adaptor.SelectCommand() = New SQLBaseCommand("SELECT COMPANY_ID,COMPANY_NAME FROM COMPANY", myConnection)
Dim ds = New DataSet()
adaptor.Fill(ds, "COMPANY")
Dim myArray As New ArrayList
For Each row As DataRow In ds.Tables(0).Rows
myArray.Add(row)
Next
MsgBox(myArray(1).Item(0)) //This shows 102
MsgBox(myArray(1).Item(1)) //This shows Maui Mu-Mus
Return myArray
So myArray
is storing the right values; however in my MVC Controller i got an arrayList with 23 rows(which is fine) but all of them empty.
Here is my Controller Code GET: /Gupta/GetCiudades
Function GetCiudades() As JsonResult
Dim objConn As Object
objConn = Server.CreateObject("TestGupta.ComClass1")
Dim ciudadJson As ArrayList = objConn.getCompanies()
Return Json(ciudadJson, JsonRequestBehavior.AllowGet)
End Function
Ajax Code
:
$.getJSON("Gupta/GetCiudades", null, function (ciudades) {
ciudades = (JSON.stringify(ciudades));
console.log(ciudades);
});
console.log Result:
[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}]
The question is: if in the com object is showing the right values, then why in the controller the rows are empty??
Fixed:
Com+ Code:
Public Function getCompanies()
Dim myConnection As SQLBaseConnection = New SQLBaseConnection()
myConnection.ConnectionString = getConn ' Obtenemos la cadena de conexion desde el get
'Abrimos la conexion con Gupta
myConnection.Open()
Dim adaptor = New SQLBaseDataAdapter
adaptor.SelectCommand() = New SQLBaseCommand("SELECT COMPANY_ID,COMPANY_NAME FROM COMPANY", myConnection)
Dim ds = New DataSet()
adaptor.Fill(ds, "COMPANY")
myConnection.Close()
Return ds
End Function
Controller Call
Dim ds = objConn.getCompanies()
Dim arrayInformaticos As New ArrayList
For i = 0 To ds.Tables(0).Rows.Count - 1
arrayInformaticos.Add(New Informatico(ds.Tables(0).Rows(i).Item(0), ds.Tables(0).Rows(i).Item(1)))
Next
Return Json(arrayInformaticos, JsonRequestBehavior.AllowGet)
Solution based on ArrayList of Objects in the controller, and now the Com method returns a Dataset.