Hi there, i'm new here, as you may see heh.
Anyways, i have a problem passing parameters to an SQL stored procedure.
Im still new to SQL, especially to Stored procedures and parameters, so it might be a stupid question.
This is the stored procedure:
CREATE PROCEDURE checkBooking
AS
DECLARE @ScheduleID varchar(50)
DECLARE @ScreenColumn int
DECLARE @ScreenRow int
Select * from tblBooking where BookingScheduleID = @ScheduleID AND BookingScreenRow = @ScreenRow AND BookingScreenColumn = @ScreenColumn
This is supposed to accept 3 parameters and return all the data back to the user.
When i try to input the parameters through C# i always get this error:
'Procedure checkBooking has no parameters and arguments were supplied.'
I tried it in two ways but i still get this error
This is the first attempt in C#:
comm.CommandText = "checkBooking";
comm.CommandType = CommandType.StoredProcedure;
comm.Parameters.AddWithValue("@ScheduleID", selectedScheduleID);
comm.Parameters.AddWithValue("@ScreenColumn", column);
comm.Parameters.AddWithValue("@ScreenRow", row);
This is the second:
comm.Parameters.Add("@ScheduleID", SqlDbType.VarChar);
comm.Parameters[0].Value = selectedScheduleID;
comm.Parameters[0].Direction = ParameterDirection.Input;
comm.Parameters.Add("@ScreenColumn", SqlDbType.Int);
comm.Parameters[1].Value = column;
comm.Parameters[1].Direction = ParameterDirection.Input;
comm.Parameters.Add("@ScreenRow", SqlDbType.Int);
comm.Parameters[2].Value = row;
comm.Parameters[2].Direction = ParameterDirection.Input;
Am i doing something wrong with the way i pass the parameters? or perhaps the sql is just wrong?
Please help, Regards and thanks.
Loading

Kirtan PatelRank #292 · 8.6K reputationPosted Jun 1, 2009, 11:29 AM EDT
CREATE PROCEDURE checkBooking ( @ScheduleID varchar(50), @ScreenColumn int, @ScreenRow int ) AS Select * from tblBooking where BookingScheduleID = @ScheduleID AND BookingScreenRow = @ScreenRow AND BookingScreenColumn = @ScreenColumnand Your First Attempt Code is Right as it is
comm.CommandText = "checkBooking"; comm.CommandType = CommandType.StoredProcedure; comm.Parameters.AddWithValue("@ScheduleID", selectedScheduleID); comm.Parameters.AddWithValue("@ScreenColumn", column); comm.Parameters.AddWithValue("@ScreenRow", row);Michael Richards5 reputationPosted Jun 2, 2009, 12:37 AM EDT
Thanks
Kirtan PatelRank #292 · 8.6K reputationPosted Jun 2, 2009, 2:30 AM EDT
Michael Richards5 reputationPosted Jun 2, 2009, 2:55 AM EDT
Thanks a lot for your help.
Turns out i wasn't clearing the parameters before and since the code was ran more then once it gave an error.
comm.Parameters.Clear();
That's all.
It was a stupid error. Thanks.