Procedure or function expects parameter which was not supplied.
SqlCommand cmd = new SqlCommand("Execute SPInsertLocal @PON,@TCode,@Qty,@Type,@RES", con);
I was not passing the parameter , fixed the issue
Stored procedure or function expects parameter which is not supplied
Your stored procedure expects 5 parameters as input
@userID int,
@userName varchar(50),
@password nvarchar(50),
@emailAddress nvarchar(50),
@preferenceName varchar(20)
So you should add all 5 parameters to this SP call:
cmd.CommandText = "SHOWuser";
cmd.Parameters.AddWithValue("@userID",userID);
cmd.Parameters.AddWithValue("@userName", userName);
cmd.Parameters.AddWithValue("@password", password);
cmd.Parameters.AddWithValue("@emailAddress", emailAddress);
cmd.Parameters.AddWithValue("@preferenceName", preferences);
dbcon.Open();
PS: It's not clear what these parameter are for. You don't use these parameters in your SP body so your SP should looks like:
ALTER PROCEDURE [dbo].[SHOWuser] AS BEGIN ..... END
C# Stored procedure or function expects parameter which is not supplied
You have stated:
cmd.CommandType = CommandType.Text;
Therefore you are simply executing:
SP_getName
Which works because it is the first statement in the batch, so you can call the procedure without EXECUTE
, but you aren't actually including the parameter. Change it to
cmd.CommandType = CommandType.StoredProcedure;
Or you can change your CommandText to:
EXECUTE SP_getName @username;
As a side note you should Avoid using the prefix 'sp_' for your stored procedures
And a further side note would be to use using
with IDisposable objects to ensure they are disposed of correctly:
using (var connection = new SqlConnection("ConnectionString"))
using (var cmd = new new SqlCommand("SP_getName", connection))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@username", SqlDbType.NVarChar).Value = "bob101";
connection.Open();
using (var reader = command.ExecuteReader())
{
while (reader.Read())
{
// Do something
}
}
}
Procedure or function expects parameter which was not supplied
This typically occurs if the object supplied as the value of your SQL parameter is NULL, but the stored procedure does not allow null values (which yours does not). You can set a conditional breakpoint on this line sqlcomm.Parameters.AddWithValue("@Election_ID", eventid)
to make sure the eventid
parameter is not null.
It might also be a good idea to use defensive coding, and in your getAvailableSMSNumbers function, check to make sure eventid
is not null, and if it is, throw an exception or provide some type of feedback for the user.
Procedure or function '...' expects parameter '...', which was not supplied.'
May be ID_interno_disp column is set as identity column.
In that case there is no need to pass paramater for this column at all.
so remove parameter for it.
Add below after Insert statement
SELECT SCOPE_IDENTITY() AS 'Identity'
--this will return identity value inserted only within the current scope
SELECT @@IDENTITY AS 'Identity';
--this is not limited to a specific scope
This will give you the autoincremented Id for the latest record.
And then you can use this id to insert in to other table Bi_dispositivo
Procedure expects parameter which was not supplied
I would check my application code and see what value you are setting @template to. I suspect it is null and therein lies the problem.
Stored procedure or function expects parameter which was not supplied
You need to use SqlCommand.Parameters.AddWithValue
:
cmd.Parameters.AddWithValue("@ParameterName", value);
or SqlCommand.Parameters.Add
for other data types:
cmd.Parameters.Add("@ParameterName", SqlDbType.Int, 5);
cmd.Parameters["@ParameterName"].Value = value;
SqlCommand.Parameters.AddWithValue
replaces the ambiguous overload of Add
that took a string and object parameter. See MSDN for more info.
Related Topics
Delete Duplicate Rows (Don't Delete All Duplicate)
Safely Rename Tables Using Serial Primary Key Columns
What's the Difference Between Varchar and Char
What MySQL Database Tables and Relationships Would Support a Q&A Survey With Conditional Questions
How to Turn Identity_Insert on and Off Using SQL Server 2008
Physical Vs. Logical (Hard Vs. Soft) Delete of Database Record
Find Most Frequent Value in SQL Column
Rounding Off to Two Decimal Places in Sql
Simulate Create Database If Not Exists For Postgresql
SQL Statement to Select All Rows from Previous Day
Sql: Between VS ≪= and ≫=
SQL Select Speed Int VS Varchar
MySQL Not Using Indexes With Where in Clause
How to Use Join For Two Different Database Tables