Click here to Skip to main content
15,994,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

VB
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)
Posted
Comments
Maciej Los 1-Aug-13 5:50am    
And the body of SP is...

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.
 
Share this answer
 
Comments
IanMac91 1-Aug-13 5:50am    
Hi. Thanks for your reply! I tried this and still get the same message. My stored procedure can be found below. Perhaps there is a problem with it?

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[vs_PM_SelectDates]

As

Begin

Declare @Param1 As DateTime

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
Hi IanMac91,

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

SQL
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
 
Share this answer
 
Comments
IanMac91 1-Aug-13 5:59am    
Thank you! This worked!
Quote:
"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..
SQL
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900