how to revise exising SP to handle parameter passed from ashx to sp ?
how to revise exising SP to handle parameter passed from ashx to sp ?
(OP)
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
http://172.20.100.12:888/rpt_vehicle.ashx?cardno=0...='2/1/2018'&txtCompleted_Date='2/9/2018'
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
---------------------- $_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
http://172.20.100.12:888/rpt_vehicle.ashx?cardno=0...='2/1/2018'&txtCompleted_Date='2/9/2018'
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

RE: how to revise exising SP to handle parameter passed from ashx to sp ?
CODE
There is no need to pass the Page object to the method, just simply try this:
CODE
RE: how to revise exising SP to handle parameter passed from ashx to sp ?
After adding your statement into ashx..it always showed context is not declared..
Btw,could you pls help me to finetune this previous SP where it receive 3 parameters which are cardno, month , year.. so that it can pass
my required 3 parameter (cardno,txtLog_date, txtCompleted_date)
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
-- Batch submitted through debugger: db-deploy.sql|6|0|C:\CorpServer\ATTD\Report\db-deploy.sql
Alter PROC [dbo].[$_Rpt_vehicle]
@Card VARCHAR(16), -- Employee Card No.
@Year INT, -- Trx. Year
@Mnth INT, -- Trx. Month
@txtLog_date datetime,
@txtCompleted_date datetime
AS SET NOCOUNT ON
BEGIN
DECLARE @Temp TABLE ( [Id] INT IDENTITY(1,1), [Date] DATETIME, [WDay] NVARCHAR(100) )
DECLARE @DtFr DATETIME, @DtTo DATETIME
SET @DtFr = CAST(CAST(@Year AS VARCHAR) + '/' + CAST((@Mnth+0) AS VARCHAR) + '/01' AS DATETIME)
SET @DtTo = DATEADD(month, 1,CAST(CAST(@Year AS VARCHAR) + '/' + CAST((@Mnth+0) AS VARCHAR) + '/01' AS DATETIME))
;WITH tData AS
( SELECT @DtFr [Date] UNION ALL SELECT DATEADD(DAY,1,[Date]) FROM tData WHERE DATEADD(DAY,1,[Date]) < @DtTo )
INSERT INTO @Temp ( [Date], [WDay] ) SELECT mt.[Date], DATENAME(WEEKDAY,mt.[Date]) FROM tData mt
SELECT
'',
CardNo [EmplCard], Name [EmplName], [DepartmentDesc] [EmplSrcs], [InOut] [InOutDes],
TrDate [TrnxDate], TrTime [TrnxTmMn], TrController [TrnxTmMx],
''
FROM VW_RPT_van2
WHERE
CardNo = @Card AND trdate between @txtLog_Date and @txtCompleted_Date
GROUP BY
TrDate, [TrDay], TrTime, CardNo, Name, [DepartmentDesc], [InOut] , TrController
END
---------------------- end of sp -----------------------------------
RE: how to revise exising SP to handle parameter passed from ashx to sp ?
YOu need to step through each line to find where the problem starts