Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am insert udpate delete the data using single procedure but i am get an this type of error my table contain a three colums.. customerid name country

this is my procedure

SQL
alter procedure sp_customers_Add(@action varchar(10), @customerid int, @name varchar(20), @country varchar(20))
as
begin

if @action='SELECT'
begin
select customerid ,name ,country from customers
end

if @action='INSERT'
begin
insert into customers(name,country)values(@name,@country)
end

if @action='UPDATE'
begin
Update customers set name=@name,country=@country where customerid=@customerid
end

if @action='DELETE'
begin
Delete from customers where customerid=@customerid
end
end


Please help me..

What I have tried:

Procedure or function 'sp_customers_Add' expects parameter '@customerid', which was not supplied.
Posted
Updated 29-Aug-16 22:09pm
Comments
phil.o 30-Aug-16 4:01am    
PLease show the code block where you are calling your stored procedure. Obviously the problem does not lie in the stored procedure itself, but rather how you are calling it.
Member 12599631 30-Aug-16 4:22am    
string name = txtname.Text;

string country = txtcountry.Text;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("sp_customers_Add"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Action", "INSERT");
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Country", country);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindGrid();
phil.o 30-Aug-16 4:35am    
You have to provide the customerId parameter, even if it is not used in the query.
cmd.Parameters.AddWithValue("@Customer", DBNull.Value);
Member 12599631 30-Aug-16 5:20am    
Thanks so much

1 solution

The error message is pretty much self explanatory:
Procedure or function 'sp_customers_Add' expects parameter '@customerid', which was not supplied.
Your procedure is defined as having four parameters, one of which is called @customerid but when you call the SP from your external code you do not provide a value for that parameter.
So check your code, and make sure that you:

1) Provided four parameters with values.
2) Spelled the parameter name correctly.
3) Provided a value that isn't null or DBNull.Value

We can't do that for you, I'm afraid!
 
Share this answer
 
Comments
Member 12599631 30-Aug-16 4:25am    
string name = txtname.Text;

string country = txtcountry.Text;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("sp_customers_Add"))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Action", "INSERT");
cmd.Parameters.AddWithValue("@Name", name);
cmd.Parameters.AddWithValue("@Country", country);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
this.BindGrid();

i give the identity(1,1) for customerid in database
OriginalGriff 30-Aug-16 4:35am    
Look at your code and the list of "to do's" I suggested:
1) Provided four parameters with values.
Did you provide four parameters?
Member 12599631 30-Aug-16 5:27am    
thanks
OriginalGriff 30-Aug-16 5:33am    
You're welcome!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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