0
試圖從.asmx頁面獲取純JSON並使用SQL調用。似乎無法得到它。我發現的每一篇文章都是在c#中,或者不是我所追求的。序列化會導致1維數組問題。我需要從我的Web服務器上的MS訪問數據庫獲取數據,以獲取小型Java應用程序。需要將示例VB.NET對象添加到JSON
<%@ WebService class="GetDBStudent" %>
Imports System.Web
Imports System.Web.Services
Imports System.Xml
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.Data
imports System.Web.Script.Serialization
'<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="com.mcfrsit.GetDBStudent")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
Public Class GetDBStudent
Inherits System.Web.Services.WebService
Public Class Students
Public StudentID As String
Public LastName As String
Public FirstName As String
Public Affiliation As String
Public ClassName As String
Public DateCompleted As DateTime
End Class
<WebMethod()> _
<ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json)> _
Public Function GetArray() As Students()
' Create a connection string
Dim DBConnection As String = ConfigurationManager.ConnectionStrings("OdbcServices").ToString
Dim sql As String = "SELECT * FROM ClassRecordsEnrollmentsQry WHERE [Affiliation] = 'DFRS'"
Dim Conn As New ADODB.Connection()
Dim rs As New ADODB.Recordset()
Dim daTitles As New Data.OleDb.OleDbDataAdapter()
Dim dsTitles As New DataSet("CrossTab")
Conn.Open(DBConnection, "", "", -1)
Try
rs.Open(sql, DBConnection, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic, 1)
daTitles.Fill(dsTitles, rs, "Students")
'create object array, using row count as upper dim
Dim objStudents As Students() = New Students(dsTitles.Tables(0).Rows.Count - 1) {}
'loop through dataset to add data to object array
Dim intRsCount As Int16
For intRsCount = 0 To dsTitles.Tables(0).Rows.Count - 1
Dim intCsCount As Int16
For intCsCount = 0 To dsTitles.Tables(0).Columns.Count - 1
'Dim strColName As String = dsTitles.Tables(0).Columns(intCsCount)
Next
objStudents(intRsCount) = New Students
objStudents(intRsCount).StudentID = dsTitles.Tables(0).Rows(intRsCount)(0)
objStudents(intRsCount).LastName = dsTitles.Tables(0).Rows(intRsCount)(1)
objStudents(intRsCount).FirstName = dsTitles.Tables(0).Rows(intRsCount)(2)
objStudents(intRsCount).Affiliation = dsTitles.Tables(0).Rows(intRsCount)(3)
objStudents(intRsCount).ClassName = dsTitles.Tables(0).Rows(intRsCount)(4)
objStudents(intRsCount).DateCompleted = dsTitles.Tables(0).Rows(intRsCount)(5)
Next
'Return new JavaScriptSerializer().Serialize(objStudents)
Return objStudents
Catch ex As Exception
'Response.Write("Sorting is not supported in the view")
Finally
Conn.Close()
End Try
End Function
End Class