【问题标题】:MVC Controller and Com Object VB .NetMVC 控制器和 Com 对象 VB .Net
【发布时间】:2014-05-30 14:44:46
【问题描述】:

我有一个开发项目,我制作了一个 Com dll 来与 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

所以myArray 存储了正确的值;但是在我的 MVC 控制器中,我得到了一个 23 行的数组列表(这很好),但它们都是空的。

这是我的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:

[{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}] 

问题是:如果在 com 对象中显示正确的值,那么为什么在控制器中的行是空的??

【问题讨论】:

  • 所以 myArray 存储了正确的值;但是在我的 MVC 控制器中,我得到了一个有 23 行的数组列表(这很好),但它们都是空的....为什么??

标签: .net vb.net visual-studio-2010 sqlbase


【解决方案1】:

固定:

Com+ 代码:

 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

控制器调用

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)

基于控制器中的ArrayList的解决方案,现在Com方法返回一个Dataset。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-13
    • 2012-04-11
    • 2023-03-28
    • 2010-11-06
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    相关资源
    最近更新 更多