Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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
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 21-Dec-12 7:30am
Rate this: bad
good
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.
  Permalink  
Comments
okishore7 at 21-Dec-12 12:38pm
   
same error
__TR__ at 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 at 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__ at 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 at 21-Dec-12 13:18pm
   
inserting
okishore7 at 22-Dec-12 0:06am
   
++5
 
THANK you --TR---
Rate this: bad
good
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
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2014
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