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

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> How To Revise Parameter Passing From Integer To Datetime In My Ashx    
 
   
smyeong
post Jan 26 2018, 11:28 PM
Post#1



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


Hi, there.
I was having problem in passing asp parameter to my store procedure in SQL server.
I tried to change the parameter 'year' to txtLog_Date and 'month' to txtCompleted_Date

Earlier asp page goes like this with 2 parameters
http://172.20.100.12:888/rpt_Detail_dept.a...018&month=1

Expected asp page
http://172.20.100.12:888/rpt_vehicle.ashx?...;1/27/2018'

This asp would call up rpt_Detail_dept.ashx and the file would be as below :

<%@ 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 ----------------------------------------------------

So, how can I revise above coding to match my parameter 'txtLog_Date' and 'txtCompleted_Date in above coding.
And how can I revise my store procedure to have these 2 parameter well defined

----------------- Store procedure -----------------------------------------------
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 [EmplCard],trdate
FROM VW_RPT_van2
where
cardno = @Card
and
trdate between @txtLog_Date and @txtCompleted_Date

END
-------------------------- end of store procedure -----------------

Appreciate your input here..
many thanks


Go to the top of the page
 
GroverParkGeorge
post Jan 27 2018, 09:56 AM
Post#2


UA Admin
Posts: 36,023
Joined: 20-June 02
From: Newcastle, WA


First, where are those page links supposed to take us? I am uncertain, but they seem to be links to YOUR own computer, i.e. "172.20.100.12:888" would be a local host that you are using for debugging. Is that right?

Second, you refer to "ashx" pages, which, in my limited understanding would be a page that is used by other, valid web pages, to retrieve certain information. So, just to be clear, is that what you are talking about here?

Third, your specific question seems to be how to change references that point to controls on a web page containing a "Month" value or a "Year" value to references that point to controls containing full dates, i.e. Month/Day/Year, for log date and completed date. Is that correct?

If so, you can probably accomplish this by changing the lines of code that refer to those controls on the page, something like this (which is aircode and probably needs further tweaking).

...Code Lines

dComm.Parameters.Add(New SqlParameter("@LogDate", txtLog_Date))
dComm.Parameters.Add(New SqlParameter("@CompletedDate", txtCompletedDate))

...Code Lines

I think with those changes passed into the Stored Proc shown, you should get a result.

However, further testing (and probably some additional modifications) on your part will be required also.
Go to the top of the page
 
smyeong
post Jan 28 2018, 09:34 PM
Post#3



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


Thanks Grover for the input. I am not familiar at writing asp or ashx or even sp in SQL.. I need to clarify again for my question. See attached photo.
first, I got one original asp where it would pass cardno, year and month to ashx page, then call sp...
second, I had modified the asp page and pass cardno, txtlog_date, txtCompleted_date to ashx , then call sp..
but, I just don't know how to rewrite the ashx and sp so that the ashx is able to generate pdf file. FYI, the download button would generate PDF

Can you check the function in ashx, how to rewrite and pass txtlog_date ? txtlog_date would be in datetime format mmddyyyy

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

----------------------------------------------

third, is my sp coding correctly done ?
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 [EmplCard],trdate
FROM VW_RPT_van2
where
cardno = @Card
and
trdate between @txtLog_Date and @txtCompleted_Date

END

------------------------------------ Sp -----------------------------------

Thanks
This post has been edited by smyeong: Jan 28 2018, 09:35 PM
Attached File(s)
Attached File  ashx_sp.png ( 45.06K )Number of downloads: 2
 
Go to the top of the page
 
GroverParkGeorge
post Jan 28 2018, 11:34 PM
Post#4


UA Admin
Posts: 36,023
Joined: 20-June 02
From: Newcastle, WA


I have no experience with this sort of coding.

I was focusing on the syntax for the Stored Proc, which SHOULD be the same in any context. It certainly looks appropriate, but the way to test it is to put it into SSMS and try to call it there, with dummy parameters.

Sorry.
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    12th November 2019 - 09:40 PM