UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Closed TopicStart new topic
> How To Re-code Ashx For Correct Parameter, asp.net    
 
   
smyeong
post Feb 2 2018, 01:21 AM
Post#1



Posts: 404
Joined: 6-November 02
From: Malaysia


http://172.20.100.12:888/rpt_vehicle.ashx?...9;2/3/2018'

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 :
http://172.20.100.12:888/rpt_Detail_dept.a...018&month=2

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











Attached File(s)
Attached File  ashx_sp.png ( 45.06K )Number of downloads: 10
 
Go to the top of the page
 
GroverParkGeorge
post Feb 2 2018, 08:02 AM
Post#2


UA Admin
Posts: 35,502
Joined: 20-June 02
From: Newcastle, WA


You have repeatedly posted this identical question. You will get no better answers by doing that.

Please stop repeating the same question. Stick to the ORIGINAL thread and follow up there.

I'm locking this and all of the other duplicates.

Note that I've addressed the issues in one of the previous threads. If that didn't solve your problem, follow up there with what you did and what the results were.

George Hepworth
Member, UA Admin Team
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    17th August 2019 - 08:15 AM