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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Re-code Ashx For Correct Parameter, asp.net

Status
Not open for further replies.
Feb 5, 2018
1
MY
How To Re-code Ashx For Correct Parameter, asp.net

02-02-2018 04:28 PM|LINK



Hi, all.
Attached is showing how the 3 parameters are passed to ahsx asp.net. But in the ashx, it would use something like as below :

--- -----

This is to select all the record based on month.
Now my requirement is to change to cardno=0000055799&txtLog_Date='2/2/2018'&txtCompleted_Date='2/3/2018'

can somebody help to revise below ashx coding so that it can pass correct parameter to my store procedure in MSsql..

<%@ WebHandler Language="VB" Class="rpt_Detail_Dept" %>

Imports Microsoft.Reporting.WebForms

Public Class rpt_Detail_Dept : 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 = "[$_RptDetail]"
dComm.CommandType = CommandType.StoredProcedure
dComm.Parameters.Add(New SqlParameter("@Card", CardNo(Page)))
dComm.Parameters.Add(New SqlParameter("@Mnth", Month(Page)))
dComm.Parameters.Add(New SqlParameter("@Year", Year(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_Detail_Dept.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 Month(Page As HttpContext) As Int32
Get
Dim iData As Int32

If Not Double.TryParse(Page.Request.QueryString("month"), iData) Then iData = Now.Month

Return iData
End Get
End Property

Public ReadOnly Property Year(Page As HttpContext) As Int32
Get
Dim iData As Int32

If Not Double.TryParse(Page.Request.QueryString("year"), iData) Then iData = Now.Year

Return iData
End Get
End Property

End Class

--------------------------- end of ashx ------------------------------------------------------------


Above ashx will pass the parameter to sp as below :

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

AS SET NOCOUNT ON


BEGIN
set @card = @card

SELECT cardno, trdate
FROM VW_RPT_van2
where
cardno = @Card
and
trdate between @txtLog_Date and @txtCompleted_Date

END
----------------------------- end of sp --------------------------


FYI, my sp is able to display all those record which are based on cardno and txtlog_date and txtCompleted_date
how can I modify the ashx so that I can display record on my asp page?

TQ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top