Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to revise exising SP to handle parameter passed from ashx to sp ?

Status
Not open for further replies.

yeongsm

MIS
Dec 13, 2011
3
MY
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
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[smile2]




 
You will have to debug through your code that is getting the querystring value:
Code:
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

There is no need to pass the Page object to the method, just simply try this:
Code:
   context.Request.QueryString("cardno")

 
Hi, Benson
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 -----------------------------------










 
Where are you getting the error, what line?
YOu need to step through each line to find where the problem starts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top