Click here to Skip to main content
12,758,918 members (33,746 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# C#4.0
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
insert into EMP1(Empname,EmpSalary)values (@Name,@Sal)
select @Id=@@Identity

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()

private void button1_Click(object sender, EventArgs e)
SqlConnection con = new SqlConnection(helpercs.connectionstring);
SqlCommand cmd = new SqlCommand("insertEmp", con);
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);
txtid.Text = parId.Value.ToString();


plz help me i tried for about 2hours
Posted 21-Dec-12 7:30am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
okishore7 21-Dec-12 12:38pm
same error
__TR__ 21-Dec-12 12:47pm
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
okishore7 22-Dec-12 0:06am

THANK you --TR---
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

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

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100