Advertisement
ScottBeeson

Untitled

Sep 4th, 2013
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.52 KB | None | 0 0
  1. Imports System.Web.Services
  2. Imports System.Web.Services.Protocols
  3. Imports System.ComponentModel
  4. Imports System.Data
  5. Imports System.Data.SqlClient
  6. Imports System.ServiceModel.Web
  7. Imports System.Web.Script.Serialization
  8. Imports System.Web.Script.Services
  9.  
  10. <System.Web.Script.Services.ScriptService()> _
  11. <ToolboxItem(False)> _
  12. Public Class reportdata
  13.     Inherits System.Web.Services.WebService
  14.     Dim connectionString = "redacted"
  15.  
  16.  
  17.     <WebMethod()> _ 'This is the old function
  18.     <WebGet(ResponseFormat:=WebMessageFormat.Json)> _
  19.     Public Function rptPendingServerRequestsOld() As DataSet
  20.         Dim connection As SqlConnection
  21.         Dim command As SqlCommand
  22.         Dim adapter As New SqlDataAdapter
  23.         Dim ds As New DataSet
  24.         Dim sql As String
  25.         sql = "redacted"
  26.  
  27.         connection = New SqlConnection(connectionString)
  28.  
  29.         Try
  30.             connection.Open()
  31.             command = New SqlCommand(sql, connection)
  32.             adapter.SelectCommand = command
  33.             adapter.Fill(ds)
  34.             adapter.Dispose()
  35.             command.Dispose()
  36.             connection.Close()
  37.             Return ds
  38.  
  39.         Catch ex As Exception
  40.         End Try
  41.     End Function
  42.  
  43.     <WebMethod()> _ 'this is the new one that I want to return JSON
  44.     <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
  45.     Public Function rptPendingServerRequests() As Generic.List(Of request)
  46.         Dim _conn As SqlConnection = New SqlConnection(connectionString)
  47.         Dim _dr As SqlDataReader
  48.         Dim Sql As String = String.Empty
  49.         Sql += "redacted"
  50.  
  51.         Try
  52.             Dim _cmd As SqlCommand = New SqlCommand(Sql, _conn)
  53.             _conn.Open()
  54.             _dr = _cmd.ExecuteReader(CommandBehavior.CloseConnection)
  55.  
  56.             If _dr.HasRows Then
  57.                 Dim s As request
  58.                 Dim c As New Generic.List(Of request)
  59.                 While _dr.Read
  60.                     s = New request
  61.                     With s
  62.                         .requestID = _dr("request_id")
  63.                         .status = _dr("status")
  64.                         .requester = _dr("req_by_user_id")
  65.                         .assignee = _dr("user_id")
  66.                         .nextAction = _dr("description")
  67.                     End With
  68.                     c.Add(s)
  69.                 End While
  70.  
  71.                 Return c
  72.             End If
  73.  
  74.         Catch ex As Exception
  75.             MsgBox(ex.Message)
  76.         Finally
  77.             _conn.Close()
  78.         End Try
  79.  
  80.     End Function
  81.  
  82. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement