Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ ASP and VBScript _ How To Revise Exising Sp To Handle Parameter Passed From Ashx To Sp ?

Posted by: smyeong Feb 8 2018, 09:49 PM

Hi, there. I have created a new sp in SQL but it failed to show specific records which are based on the parameters captured in ashx page from ASP page. See attached photo how I pass 3 parameters from asp to ashx then call SP...

---------------------- $_rpt_vehicle --------------------------------

set QUOTED_IDENTIFIER OFF
GO
ALTER PROC [dbo].[$_Rpt_vehicle]
@Card VARCHAR(16),
@txtLog_Date Datetime,
@txtCompleted_Date Datetime

AS SET NOCOUNT ON


BEGIN

SELECT mt.*
FROM VW_RPT_van2 mt
where
cardno = @Card
and
trdate between @txtLog_Date and @txtCompleted_Date
Order by TRDATE
-------------------------------- end -----------------------------------

------------------------- rpt_vehicle.ashx --------------------------------
<%@ WebHandler Language="VB" Class="rpt_vehicle" %>

Imports Microsoft.Reporting.WebForms

Public Class rpt_vehicle : Implements IHttpHandler, IRequiresSessionState
Private dConn As New SqlConnection(ConfigurationManager.ConnectionStrings("DataDB").ConnectionString)

Public Sub ProcessRequest(Page As HttpContext) Implements IHttpHandler.ProcessRequest
Try
Dim dComm As New SqlCommand("", dConn), tData As New DataTable()

dComm.CommandText = "[$_Rpt_Vehicle]"
dComm.CommandType = CommandType.StoredProcedure
dComm.Parameters.Add(New SqlParameter("@Card", CardNo(Page)))
dComm.Parameters.Add(New SqlParameter("@txtLog_Date", txtLog_Date(Page)))
dComm.Parameters.Add(New SqlParameter("@txtCompleted_Date", txtCompleted_Date(Page)))
dComm.CommandTimeout = 0

Dim dData As New SqlDataAdapter(dComm) : dData.Fill(tData) : dData.Dispose() : dComm.Dispose()
Dim iStrm As String() = Nothing, iWarn As Warning() = Nothing, iEncd As String = "", iExtn As String = "", iMime As String = ""
Dim iRepo As New LocalReport(), iData As New ReportDataSource()

iData.Name = "tMain" : iData.Value = tData
iRepo.ReportPath = Page.Server.MapPath("~/rpt_vehicle.rdlc")
iRepo.DataSources.Add(iData)

Dim iByte As Byte() = iRepo.Render("PDF", Nothing, iMime, iEncd, iExtn, iStrm, iWarn)

Page.Response.Buffer = True
Page.Response.Clear() : Page.Response.ContentType = iMime
Page.Response.AppendHeader("content-disposition", "attachment; filename=" & Now.ToString("yyyyMMdd_HHmmss") & "." & iExtn)
Page.Response.OutputStream.Write(iByte, 0, iByte.Length)
Page.Response.Flush()
Catch ex As Exception
Page.Response.ContentType = "text/html" : Throw ex
Finally
If Not dConn.State = ConnectionState.Closed Then dConn.Close()
End Try
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

Public ReadOnly Property CardNo(Page As HttpContext) As String
Get
Dim iData As String

If Not String.IsNullOrWhiteSpace(Page.Request.QueryString("cardno")) Then
iData = Page.Request.QueryString("cardno")
Else
iData = ""
End If

Return iData
End Get
End Property

Public ReadOnly Property txtLog_Date(Page As HttpContext) As DateTime
Get
Dim iData As DateTime

If Not DateTime.TryParse(Page.Request.QueryString("txtLog_Date"), iData) Then iData = DateTime.Now

Return iData
End Get
End Property

Public ReadOnly Property txtCompleted_Date(Page As HttpContext) As DateTime
Get
Dim iData As DateTime

If Not DateTime.TryParse(Page.Request.QueryString("txtCompleted_Date"), iData) Then iData = DateTime.Now

Return iData
End Get
End Property

End Class

----------------------------------- end ----------------------------------------------------

my asp goes like this
<<Removed Link to external website per our guidelines>>
Pls advise how I can revise my sp so that I can show all the records based on above parameter passing..?
FYI, the SQL view VW_RPT_van2 written in sp is well tested and able to show all required records.

Thanks