Click here to Skip to main content
15,896,726 members

SQL Stored Procedure expects parameter, which was not supplied.

okishore7 asked:

Open original thread
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
Tags: C# (C# 4.0)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900