将日期参数传递给存储过程。 [英] Passing date parameter to stored procedure.

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

问题描述




我编写了以下代码,当我注释掉Parameters.Add行时,它会起作用。我一直收到一条错误消息:



程序vs_PM_SelectDates没有参数和参数提供



我用几种不同的方式重写了这条线,但运气不好。如果有人能解释如何解决我的问题,我将非常感激。



Hi
I wrote the following code, which works when I comment out the Parameters.Add line. I keep getting an error message saying:

"Procedure vs_PM_SelectDates has no parameters and arguments were supplied"

I rewrote the line several different ways, but with little luck in getting it working. If someone could explain how to correct my problem I would be very grateful.

Dim Today As DateTime = DateTime.Today
Dim SelectDates As New SqlCommand("vs_PM_SelectDates", Connection)
SelectDates.CommandType = CommandType.StoredProcedure
SelectDates.Parameters.Add("@Param1", SqlDbType.DateTime).Value = Today
PMDataAdapter.SelectCommand = SelectDates
PMDataAdapter.Fill(PMDataTable)

推荐答案





尝试更换,



SelectDates.Parameters.Add(@ Param1,SqlDbType.DateTime).Value =今天



with



SelectDates.Parameters.AddWithValue(你的参数名称,今天)



注意: - 这里你的参数名称应该是sp中的参数名称(vs_PM_SelectDates)



希望它有所帮助。
Hi,

Try replacing,

SelectDates.Parameters.Add("@Param1", SqlDbType.DateTime).Value = Today

with

SelectDates.Parameters.AddWithValue("your parameter name", Today)

Note :- Here "your parameter name"should be parameter name in your sp ("vs_PM_SelectDates")

Hope it helps.


你好IanMac91,



问题出在您的存储过程中。请参阅下面的更新存储过程。



Hi IanMac91,

Problem is in your stored procedure. see updated stored procedure below.

set ANSI_NULLS ON 
set QUOTED_IDENTIFIER ON 
go 

ALTER PROCEDURE [dbo].[vs_PM_SelectDates] 
   @Param1 DateTime //Add here
As 
Begin 
Declare @Param1 As DateTime // remove this
Select [Table1].[EmployeeID], [Table2].[Dispensing ID], [Table1].[DateEntered] 
From [Table1] Inner Join [Detail] On [Table2].[ID] = [Table1].[EmployeeID] 
Where [DateEntered] > @Param1 
Order By EmployeeID, DateEntered 

End


引用:

过程vs_PM_SelectDates没有参数和参数提供

"Procedure vs_PM_SelectDates has no parameters and arguments were supplied"



错误本身是自解释的..这是状态即使存储过程需要参数也不需要参数,您将参数传递给存储过程...



您的存储过程必须像这样更改..


The Error itself is self explanatory.. It's States that Even Thought no Parameters are Required for a Stored Procedure, you are Passing the Parameter to the Stored Procedure...

Your Stored Procedure has to be Changed like this..

Use DataBase_Name
Go
set ANSI_NULLS ON
Go
Set QUOTED_IDENTIFIER ON
Go
ALTER PROCEDURE [dbo].[vs_PM_SelectDates]
@Param1 As DateTime
As
Begin
    Select t1.[EmployeeID], t2.[Dispensing ID], t1.[DateEntered]
    From [Table1] t1
    Inner Join [Detail] t2 On t2.[ID] = t1.[EmployeeID]
    Where [DateEntered] > @Param1
    Order By EmployeeID, DateEntered
End


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

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