I have my method
using (var helper = new DbHelper())
{
_commandText = "AddUpdateContactDetails";
var parameter = new[]
{
new SqlParameter("@Id", 0), // error here
new SqlParameter("@CustomerId", id),
new SqlParameter("@FirstName", customerDetails.FirstName),
new SqlParameter("@LastName", customerDetails.LastName),
new SqlParameter("@CompanyName", customerDetails.Company),
new SqlParameter("@Designation", customerDetails.DesigId),
new SqlParameter("@Title", customerDetails.Title),
new SqlParameter("@Email", customerDetails.Email),
new SqlParameter("@Phone", customerDetails.Phone),
};
helper.ExecuteNonQuery(_commandText, CommandType.StoredProcedure, parameter);
}
and Sp is below
Alter Procedure AddUpdateContactDetails
(
@Id int,
@CustomerId int,
@FirstName varchar(50),
@LastName varchar(50),
@CompanyName varchar(150),
@Designation int,
@Title int,
@Email varchar(50),
@Phone varchar(50)
)
AS
BEGIN
IF @Id<=0
BEGIN
INSERT INTO CustomerDetails
(FirstName,CustomerId,LastName, CompanyName, Designation, Title,Email,Phone)
VALUES
(@FirstName,@CustomerId,@LastName,@CompanyName,@Designation,@Title,@Email,@Phone )
END
ELSE
BEGIN
UPDATE CustomerDetails
SET FirstName= @FirstName ,
LastName= @LastName ,
CompanyName= @CompanyName ,
Designation= @Designation ,
Title= @Title ,
Email= @Email ,
Phone= @Phone
WHERE Id= @Id
END
END
But still getting the exception that "Procedure or function 'AddUpdateContactDetails' expects parameter '@Id', which was not supplied."