Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
error:{"Procedure or function 'insertEmp' expects parameter '@Sal', which was not supplied."}



this is my stored procedure
create PROCEDURE insertEmp(@Id int output,@Name varchar(50),@Sal money) AS
begin
insert into EMP1(Empname,EmpSalary)values (@Name,@Sal)
select @Id=@@Identity
END

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace SP2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(helpercs.connectionstring);
SqlCommand cmd = new SqlCommand("insertEmp", con);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter parId, parName, parSalary;
parId = cmd.Parameters.Add("@Id", SqlDbType.Int);
parId.Direction = ParameterDirection.Output;
parName = cmd.Parameters.Add("@name",SqlDbType.VarChar,50);
parSalary = cmd.Parameters.Add("@salary",SqlDbType.Money);
parName.Value =int.Parse(txtname.Text);
parSalary.Value =int.Parse( txtsalary.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
txtid.Text = parId.Value.ToString();


}


}
}
plz help me i tried for about 2hours
Posted

As the error says your stored procedure expects a parameter by name @Sal, but you are passing @salary from your application. Changing @salary to @sal should fix the issue.
 
Share this answer
 
Comments
okishore7 21-Dec-12 12:38pm    
same error
__TR__ 21-Dec-12 12:47pm    
Try
cmd.Parameters.Add("@name",SqlDbType.VarChar,50).Value = txtname.Text;
cmd.Parameters.Add("@sal",SqlDbType.Money).Value = txtsalary.Text;
cmd.Parameters.Add("@Id", SqlDbType.Int).Direction = ParameterDirection.Output;
txtid.Text = cmd.Parameters["@Id"].Value.ToString();
okishore7 21-Dec-12 13:07pm    
The values are updating in database ename and esalary but eid is null always and i cant see textid.text value
__TR__ 21-Dec-12 13:15pm    
Are you inserting data in your stored procedure or updating the existing data?
If you are inserting the data and the Id is null there is a possibility that IDENTITY (Property)[^] is not set on that column.
okishore7 21-Dec-12 13:18pm    
inserting
Your stored procedure is designed to add an entry to your database,
we know this because it uses the INSERT statement

So you have specified an identity using @name/@identity, but you have not specified the person salary which ought to be there.

so wherever you are CALLING the stored procedure from...
In that call you ALSO need to add the Salary amount.

You may find further information HERE
 
Share this answer
 

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