Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi frnds am inserting values in stored procedure but often am getting error as
Procedure or function 'insertvalue' expects parameter '@ename', which was not supplied.


My Table Fields are
SQL
eid	int	Unchecked  //Primary Key is Ser
ename	varchar(50)	Checked
gender	varchar(50)	Checked
dept	varchar(50)	Checked
adress	varchar(50)	Checked
age	varchar(50)	Checked
uname	varchar(50)	Unchecked
pswd	varchar(50)	Checked
cntctno	varchar(50)	Checked
		Unchecked


My stored Procedure Code

SQL
CREATE PROCEDURE dbo.insertvalue
@eid int output,
@ename varchar(50),
@gender varchar(50),
@dept varchar(50),
@adress  varchar(50),
@age  varchar(50),
@uname  varchar(50),
@pswd  varchar(50),
@cntctno  varchar(50),
@IdentitY int OUTPUT
AS
BEGIN
Insert sample (ename,gender,dept,adress,age,uname,pswd,cntctno)
Values
(@ename,@gender,@dept,@adress,@age,@uname,@pswd,@cntctno)
END
SELECT @eid  = @@IDENTITY;


My C# Code as

C#
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conect"].ConnectionString);

        con.Open();
        SqlCommand cmd = new SqlCommand("insertvalue", con);
        cmd.CommandType = CommandType.StoredProcedure;
        try
        {
            cmd.Parameters.Add("@empname", SqlDbType.VarChar).Value= objBELUserDetails.empname;
            cmd.Parameters.AddWithValue("@genderd", SqlDbType.VarChar).Value=objBELUserDetails.genderd;
            cmd.Parameters.AddWithValue("@deptmnt", SqlDbType.VarChar).Value = objBELUserDetails.deptmnt;
            cmd.Parameters.AddWithValue("@adressdetail", SqlDbType.VarChar).Value = objBELUserDetails.adressdetail;
            cmd.Parameters.AddWithValue("@ages", SqlDbType.VarChar).Value = objBELUserDetails.ages;
            cmd.Parameters.AddWithValue("@usrname", SqlDbType.VarChar).Value = objBELUserDetails.usrname;
            cmd.Parameters.AddWithValue("@paswd", SqlDbType.VarChar).Value = objBELUserDetails.paswd;
            cmd.Parameters.AddWithValue("@contctno", SqlDbType.VarChar).Value = objBELUserDetails.contctno;
            cmd.Parameters.Add("@ERROR", SqlDbType.Char, 500);
            cmd.ExecuteNonQuery();
            string strMessage = (string)cmd.Parameters["@ERROR"].Value;
            con.Close();
            return strMessage;
        }
        catch (Exception error)
        {
            throw error;
        }
        finally
        {
            cmd.Dispose();
            con.Close();
        }


pls Help me am newer to Store Procedure

Thank You..
Posted

1 solution

Try changing the parameter name:
C#
cmd.Parameters.Add("@empname", SqlDbType.VarChar).Value= objBELUserDetails.empname;
To
C#
cmd.Parameters.Add("@ename", SqlDbType.VarChar).Value= objBELUserDetails.empname;

To match the SP...
 
Share this answer
 
Comments
usha C 14-Aug-13 4:49am    
Getting The same error sir
OriginalGriff 14-Aug-13 4:53am    
Are you sure you changed it in the right bit of code? Have you checked that the objBELUserDetails.empname value is not null?
usha C 14-Aug-13 5:01am    
sir That problemis solved nw geting my error as "Procedure or function 'insertvalue' expects parameter '@IdentitY', which was not supplied."
OriginalGriff 14-Aug-13 5:05am    
I have no idea what value you are trying to put in that one - you don't even list anything vaguely similar in the SqlCommand, so it's up to you to add it. :laugh:
OriginalGriff 14-Aug-13 4:55am    
It's not the same error - look at it more closely.
This time, I think it's be complaining about @gender,, then it'll complain about @dept, and so on.
You need to match all the names in the SP to the names in the command!

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