Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
public List<employee> AddEmployee()
{
List<employee> employee = new List<employee>();
Employee objemp = new Employee();
try
{
using (SqlConnection con = new SqlConnection(cs))
{
SqlCommand cmd = new SqlCommand("sp_insert_employee_tblEmployee", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Name", objemp.Name);
cmd.Parameters.AddWithValue("@Gender", objemp.Gender);
cmd.Parameters.AddWithValue("@City", objemp.City);
cmd.Parameters.AddWithValue("@DateofJoining", objemp.Dateofjoining.ToShortTimeString());
con.Open();
cmd.ExecuteNonQuery();

}
employee.Add(objemp);
}
catch(Exception ex)
{
throw;
}
return employee;

}
}

What is wrong with this method please can anybody help me

getting following exception.


Procedure or function 'sp_insert_employee_tblEmployee' expects parameter '@Name', which was not supplied.

Procedure is --

Create procedure [dbo].[sp_insert_employee_tblEmployee]
@Name varchar(50) NULL,
@Gender varchar(50) NULL,
@City Varchar (50) NULL,
@Dateofjoining datetime
as
begin
Insert into tblEmployee values(@Name,@Gender,@City,@Dateofjoining)
End
Posted
Updated 14-Mar-15 1:57am
v2

1 solution

This happens when objemp.Name is null. You have to pass DBNull.Value instead when that happens.
 
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