Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Error has coming like this...
Sql Exception was unhandled by user code....
Procedure or function sp_userinformation has too many arguments specified.



I have written stored procedure like this

create proc sp_userinformation
(
@username varchar(20),
@password varchar(20),
@firstname varchar(20),
@lastname varchar(20),
@email varchar(20),
@phoneno varchar(20),
@location varchar(15),
@created_by varchar(20))
as
insert into userinformation(username,password,firstname,lastname,email,phoneno,location,created_by)values (@username,@password,@firstname,@lastname,@email,@phoneno,@location,@created_by)


I have written codebehind file like this


protected void btnsubmit_Click(object sender, EventArgs e)
{
if (txtpwd.Text == txtcnmpwd.Text)
{
string UserName = txtuser.Text;
string Password = txtpwd.Text;
string ConfirmPassword = txtcnmpwd.Text;
string FirstName = txtfname.Text;
string LastName = txtlname.Text;
string Email = txtEmail.Text;
string Phoneno = txtphone.Text;
string Location = txtlocation.Text;
string Created_By = txtuser.Text;
int count = 0;
SqlConnection con = new SqlConnection("Data Source=(local);Initial Catalog=sample;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("sp_userinformation", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserName", UserName);
cmd.Parameters.AddWithValue("@Password", Password);
cmd.Parameters.AddWithValue("@FirstName", FirstName);
cmd.Parameters.AddWithValue("@LastName", LastName);
cmd.Parameters.AddWithValue("@Email", Email);
cmd.Parameters.AddWithValue("@PhoneNo", Phoneno);
cmd.Parameters.AddWithValue("@Location", Location);
cmd.Parameters.AddWithValue("@Created_By", Created_By);
cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
count = cmd.ExecuteNonQuery();
message = (string) cmd.Parameters["@ERROR"].Value;

if (count>0)
{
txtuser.Text = "";
txtpwd.Text = "";
txtcnmpwd.Text = "";
txtfname.Text = "";
txtlname.Text = "";
txtEmail.Text = "";
txtphone.Text = "";
txtlocation.Text = "";

}

con.Close();

}
else
{
Page.RegisterStartupScript("UserMsg", "<Script language='javascript'>alert('" + "Password mismatch" + "');</script>");
}
//Page.RegisterStartupScript("UserMsg", "<Script language='javascript'>window.alert('" + message + "');</script>");
lblErrorMsg.Text = message;
}

while executing this,
Error has coming like this...
Sql Exception was unhandled by user code....
Procedure or function sp_userinformation has too many arguments specified.


I am the beginner.... Kindly guide me to solve this problem...

Thanks in advance...
Posted
Updated 7-Mar-13 18:17pm
v2

create proc sp_userinformation
(
@username varchar(20),
@password varchar(20),
@firstname varchar(20),
@lastname varchar(20),
@email varchar(20),
@phoneno varchar(20),
@location varchar(15),
@created_by varchar(20),
@ERROR varchar(500)output -- out put parameter
)
as
begin
begin try
begin transaction trTest
insert into userinformation(username,password,firstname,lastname,email,phoneno,location,created_by)values (@username,@password,@firstname,@lastname,@email,@phoneno,@location,@created_by)
commit transaction trTest
end try
begin catch
if @@trancount >0
rollback transaction trTest
select @ERROR =ERROR_MESSAGE()
end catch
end
 
Share this answer
 
Generally this error occurs when you are passing more parameters than the required.
So,Verify each and every parameter first.And the following code is to get the output parameter from sp.

SQL
create proc sp_userinformation
(
@username varchar(20),
@password varchar(20),
@firstname varchar(20),
@lastname varchar(20),
@email varchar(20),
@phoneno varchar(20),
@location varchar(15),
@created_by varchar(20)),
@ERROR char(500) output--add this in your sp
as
insert into userinformation(username,password,firstname,lastname,email,phoneno,location,created_by)values (@username,@password,@firstname,@lastname,@email,@phoneno,@location,@created_by) 

set @ERROR='Sucessfully Inserted' --(or your message)

and in codebehind.cs

C#
SqlParameter error_msg=New SqlParameter("@ERROR",sqldbtype.char,500);
error_msg.Direction=ParameterDirection.Output;
cmd.parameters.add(error_msg);

after the execution

you can get the value of output parameter

C#
string message=error_msg.value.ToString();
 
Share this answer
 
v2
i think u in .cs file code u are using output parameter
cmd.Parameters["@ERROR"].Direction = ParameterDirection.Output;
but u have not declared output parameter in your stored procedure .
so u must declare output parameter in your stored procedure .
 
Share this answer
 
Comments
M.Thiyagaraja 8-Mar-13 0:38am    
how to declared output parameter in stored procedure....
Thank you in advance...

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