参数未传递到存储过程 [英] Parameters are not being passed to stored Procedure

查看:91
本文介绍了参数未传递到存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个导出页面,我正在尝试使用该页面将动态创建的文件下载给用户.在主页中,我使用记录集来存储从SQL存储过程返回的数据,然后将内容转储到Grid中.
然后,我希望允许用户将网格内容另存为定界的文本文件选项卡.因此,我将它们重定向到另一页,并调用相同的SQL存储过程来填充记录集,并将其作为下载内容写入文件.
问题是参数(使用与另一页上完全相同的代码)没有传递给SQL,因此我的记录集返回为空.如果我将默认值放在SP中,则会返回记录集,并创建并下载文件.

I have an export page that I am trying to use to download a file created on the fly to the user. In the main page I use a record set to store data returned from a SQL Stored procedure and then dump the contents into a Grid.
I then want to allow the user to save the grid contents as a text file tab delimited. So i redirect them to another page and call the same SQL stored procedure to populate the recordset and write it to a file as a download.
The problem is the parameters (using the exact same code that works on the other page) are not being passed to SQL so my record set comes back empty. If I place default values in the SP the record set is returned and the file is created and downloaded.

set connUBC3=Server.CreateObject("ADODB.Connection") 
        connUBC3.Open  "UBC"	
	    If Err.number <> 0 then
		    TrapError Err.source & ": " & Err.description
	    End If
	
	    set cmdTranByCardNo = Server.CreateObject("ADODB.Command")	
		    set cmdTranByCardNo.ActiveConnection = connUBC3
		    cmdTranByCardNo.CommandText = "Transaction_GetByMerchantIdAndCardNo"
		    cmdTranByCardNo.CommandType = adCmdStoredProc
		    cmdTranByCardNo.Parameters.Add("@MerchantID", SqlDbType.nvarchar)
		    cmdTranByCardNo.Parameters("@MerchantID").Value = vMID

            cmdTranByCardNo.Parameters.Add("@CardNo", SqlDbType.nvarchar)
			cmdTranByCardNo.Parameters("@CardNo").Value = vCardNoString
				'Process results


            set SearchTranByCardNoRS = cmdTranByCardNo.Execute ' @MerchantID = vmid,@CardNo = vcardnostring	
           
            dim icount2 
            icount2 = SearchTranByCardNoRS.RecordCount	
		    If Err.number <> 0 then
			    TrapError Err.source & ": " & Err.description
		    End If

            SearchTranByCardNoRS.MoveFirst        
            if  not SearchTranByCardNoRS.eof then

                headertext = "attachment;filename=GiftTransByDate-" & vMID & fileExt
                Response.AddHeader "Content-Disposition",headertext

                Response.Write "TRANS DATE" & sCh & "TERMINAL NUMBER" & sCh & "LOCATION NAME" & sCh & "CARD NUMBER" & sCh & "TRANS  TYPE" & sCh & "TRANS AMOUNT" & sCh & "REMAINING BALANCE" & sCh & "AUTHORIZATION" & vbCrLf
                SearchTranByDateRS.MoveFirst
                do until SearchTranByCardNoRS.eof
                    Response.Write SearchTranByCardNoRS("TranDate") & sCh & SearchTranByCardNoRS("TerminalID") & sCh & SearchTranByCardNoRS("LocationName") & sCh & SearchTranByCardNoRS("CardNumber") & sCh &  SearchTranByCardNoRS("TranType") & sCh & SearchTranByCardNoRS("TranAmount") & sCh & SearchTranByCardNoRS("RemainingBal") & sCh & SearchTranByCardNoRS("AuthCode") & vbCrLf                          
                    SearchTranByCardNoRS.Movenext
                Loop
                SearchTranByCardNoRS.close
                SearchTranByCardNoRS = nothing
            End if



那么,为什么完全相同的查找在一页而不是另一页上起作用?
我在多个存储过程中都遇到相同的问题,它们都在一页上工作,但不在一页上?

感谢



So why does the exact same lookup work in one page and not the other?
I have the same problem with multiple Stored Procedures where they all work on one page but not this one?

Thanks

推荐答案

未提供与此页面关联的HTML,但可能缺少或未正确设置vMID和vCardNoString的值.我认为您需要先检查这些.

祝您好运!
The HTML associated with this page aren''t given, but the values of vMID and vCardNoString that are probably missing or not set properly. I think you need to check these first.

Good luck!


此页面上没有HTML,它是从原始页面像这样被调用的

There is no HTML on this page it is called from the original page like this

<tr>
    <td width="100%" class="caps" align="left" colspan="9">
        <img border="0" src="images/notepad-icon.jpg" align="absmiddle" width="30" height="30">Export To File  <a href="GiftCard-Export.asp?<%=Request.Querystring%>MID=<%=MIDCode %>&StartDateGC=<%=Date1 %>&EndDateGC=<%=Date2 %>&mode=GiftTransByDate&ExportStyle=tdf" target="_blank">[Tab Delimited] </a> OR  <a href="GiftCards.asp?<%=Request.Querystring%>MID=<%=MIDCode %>&Date1=<%=vDate1 %>&Date2=<%=vDate2 %>&mode=GiftTransByDate& ExportStyle=csv">[Comma Delimited]</a></img>
        <a href="GiftCards.asp?<%=Request.Querystring%>&MID=<%=MIDCode %>&StartDateGC=<%=Date1 %>&EndDateGC=<%=Date2 %>&mode=GiftTransByDate&ExportStyle=excel"><img border="0" src="images/excel_icon.gif" align="absmiddle">Export to Excel</img></a>
    </td>
</tr>


导出页面没有adovb包含文件

谢谢您的宝贵时间
The export page did not have the adovb include file

Thanks for your time


这篇关于参数未传递到存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆