I am trying to write procedure for insert value into table but the value not inserted in table
for reference I am give code which i had try for it...can anyone please help me
for insert i am try this code
public int Visitor_Insert(visitor_Master visitor_obj, common_Class comm_obj)
{
DB_Connection();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT_VISITOR";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
cmd.Parameters.AddWithValue("#VISITOR_NAME", visitor_obj.VisitorName);
cmd.Parameters.AddWithValue("#VISITOR_CONTACT", visitor_obj.VisitorContact);
cmd.Parameters.AddWithValue("#VISITOR_ADDRESS", visitor_obj.VisitorAddress);
cmd.Parameters.AddWithValue("#VISITOR_AGE", visitor_obj.VisitorAge);
cmd.Parameters.AddWithValue("#VISITOR_VEHICLENO", visitor_obj.VisitorVehicleNO);
//cmd.Parameters.AddWithValue("#VISITOR_AGE ", visitor_obj.VisitorAge);
int i = cmd.ExecuteNonQuery();
return i;
}
For Procedure I am written this code
USE [VPMS]
GO
/****** Object: StoredProcedure [dbo].[INSERT_VISITOR] Script Date: 07/24/2013 16:01:12 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[INSERT_VISITOR]
#VISITOR_NAME NVARCHAR(30),
#VISITOR_CONTACT NVARCHAR(10),
#VISITOR_ADDRESS NVARCHAR(40),
#VISITOR_AGE NVARCHAR(2),
#VISITOR_VEHICLENO NVARCHAR(20),
#VISITOR_IMAGE IMAGE,
#VISITOR_CREATEDBY NVARCHAR(20),
#VISITOR_CREDTEDON NVARCHAR(20),
#VISITOR_MODIFIEDBY NVARCHAR(20),
#VISITOR_MODIFIEDON NVARCHAR(20)
AS
DECLARE #VISITOR_ID INT,
BEGIN
SET NOCOUNT ON;
SELECT #VISITOR_ID= MAX(Visitor_Id) FROM Visitor_Master
IF (#VISITOR_ID > 0 )
BEGIN
SET #VISITOR_ID=#VISITOR_ID+1
END
ELSE
BEGIN
SET #VISITOR_ID=10
END
INSERT INTO Visitor_Master( Visitor_Id, VisitorName, Visitor_Contact, Visitor_Address, Visitor_age,
Visitor_VehicleNo, Visitor_Image, Created_By, Created_On, Modify_By, Modify_On)
VALUES(#VISITOR_ID,#VISITOR_NAME,#VISITOR_CONTACT,#VISITOR_ADDRESS,#VISITOR_AGE,#VISITOR_VEHICLENO,#VISITOR_IMAGE,#VISITOR_CREATEDBY,
#VISITOR_CREDTEDON,#VISITOR_MODIFIEDBY,#VISITOR_MODIFIEDON)
END
As you are not passing all the parameters defined in the procedure. It will throw exception.
Here I have assigned null to other parameters which you have not specified assign value as per your reqirement
ALTER PROCEDURE [dbo].[INSERT_VISITOR]
#VISITOR_NAME NVARCHAR(30),
#VISITOR_CONTACT NVARCHAR(10),
#VISITOR_ADDRESS NVARCHAR(40),
#VISITOR_AGE NVARCHAR(2),
#VISITOR_VEHICLENO NVARCHAR(20),
#VISITOR_IMAGE IMAGE = null,
#VISITOR_CREATEDBY NVARCHAR(20) = null,
#VISITOR_CREDTEDON NVARCHAR(20) = null,
#VISITOR_MODIFIEDBY NVARCHAR(20) = null,
#VISITOR_MODIFIEDON NVARCHAR(20) = null
-- rest of code
You have #VISITOR_IMAGE,#VISITOR_CREATEDBY,#VISITOR_CREDTEDON,#VISITOR_MODIFIEDBY,#VISITOR_MODIFIEDON parameters in your procedure but you have not passed value to the the above parameter.Either pass value to all the parameters or allow null
BEGIN
set #VISITOR_IMAGE = null,
set #VISITOR_CREATEDBY = null,
set #VISITOR_CREDTEDON = null,
set #VISITOR_MODIFIEDBY = null,
set #VISITOR_MODIFIEDON = null
........
Related
I'm trying to make an insert from my controller to my database. I already debug and it never enter on the exception. But i can not see the values on the db.
This is my sp:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[RegisterUser]
-- Add the parameters for the stored procedure here
#Username nvarchar(10),
#Password nvarchar(10),
#Mail nvarchar(10),
#Birthday date
AS
BEGIN
SET NOCOUNT ON
INSERT INTO Users
(
Username,
Pass,
Mail,
Birthday
)
VALUES
(
#Username,
#Password,
#Mail,
#Birthday
)
END
And on my model i used this method:
public bool registerUser(UserModel user)
{
bool isOk = false;
using (SqlConnection connection = DbConnection.OpenConnection2())
{
try
{
using (SqlCommand command = new SqlCommand("RegisterUser", connection))
{
command.CommandType = CommandType.StoredProcedure;
SqlCommandBuilder.DeriveParameters(command);
command.Parameters.Add(new SqlParameter("#UserName", SqlDbType.VarChar)).Value = user.userName.Trim();
command.Parameters.Add(new SqlParameter("#Password", SqlDbType.VarChar)).Value = user.password.Trim();
command.Parameters.Add(new SqlParameter("#Mail", SqlDbType.VarChar)).Value = user.mail.Trim();
command.ExecuteNonQuery();
}
}
catch (Exception e)
{
}
finally
{
if (connection.State.Equals(ConnectionState.Open))
{
connection.Close();
isOk = true;
}
}
}
return isOk;
}
Any ideas of why this is not working?
Thanks
Things are easy, if you use exception handling in a proper manner. You are swallowing the exception thrown by Ado.net. Follow these steps for solving your problem:
First of all you should add a throw statement in your catch block to get the exception being thrown. In production, You should catch that at later calling function or layer.
You need to provide all the parameters to your stored procedure. Currently, You are not passing one parameter named #Birthday and its value. Add this parameter with its value.
Here is the modified code that should work.
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("#UserName", SqlDbType.VarChar)).Value = user.userName.Trim();
command.Parameters.Add(new SqlParameter("#Password", SqlDbType.VarChar)).Value = user.password.Trim();
command.Parameters.Add(new SqlParameter("#Mail", SqlDbType.VarChar)).Value = user.mail.Trim();
//Assuming that the user object has a field named Birthday
command.Parameters.Add(new SqlParameter("#Birthday", SqlDbType.Date)).Value = user.Birthday;
command.ExecuteNonQuery();
If you follow my first advice, you will nearly get any other problem that is occurring in your code.
I hope it will help you somehow. Thanks!
If you prefer, you can provide a default value for the parameter #Birthday as:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[RegisterUser]
-- Add the parameters for the stored procedure here
#Username nvarchar(10),
#Password nvarchar(10),
#Mail nvarchar(10),
#Birthday date = NULL
AS
BEGIN
SET NOCOUNT ON
INSERT INTO Users
(
Username,
Pass,
Mail,
Birthday
)
VALUES
(
#Username,
#Password,
#Mail,
#Birthday
)
END
If you are not supplying "#Birthday" parameter, Please specify "#Birthday date" as "#Birthday date = NULL" in the stored procedure as below:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[RegisterUser]
-- Add the parameters for the stored procedure here
#Username nvarchar(10),
#Password nvarchar(10),
#Mail nvarchar(10),
#Birthday date = NULL
AS
BEGIN
SET NOCOUNT ON
INSERT INTO Users
(
Username,
Pass,
Mail,
Birthday
)
VALUES
(
#Username,
#Password,
#Mail,
#Birthday
)
END
Rest of your code looks all good to me.
Hope this will help you.
I need a little help with this. The stored procedure below doesn't seem to ever match exiting unique identifier
ALTER PROCEDURE [dbo].[spInsertUpdateThisStuff]
#Id uniqueidentifier OUTPUT,
#Content nvarchar(255)
AS
BEGIN
SET NOCOUNT ON;
DECLARE #tAudit table (id uniqueidentifier)
IF EXISTS(SELECT * FROM [dbo].[myData] WHERE [ID] = #Id)
-- UPDATE
BEGIN
UPDATE [dbo].[myData]
SET [ID] = #ID,
[Content] = #Content
OUTPUT inserted.[ID] INTO #tAudit
WHERE [ID] = #Id
SELECT id FROM #tAudit
END
ELSE
BEGIN
-- INSERT
SET #ID = NEWID()
INSERT INTO [dbo].CBData ([ID], [Content])
OUTPUT inserted.[ID] INTO #tAudit
VALUES(#Id, #Content)
SELECT id FROM #tAudit
END;
SET #ID = (SELECT id FROM #tAudit);
END
the C#
cmd.Parameters.Add("#ID", SqlDbType.UniqueIdentifier).Value = (currentRecord.ID == null) ? Guid.Empty : currentRecord.ID;
cmd.Parameters["#ID"].Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
currentRecord.ID = Guid.Parse(cmd.Parameters["#ID"].Value.ToString());
It seems the first IF statement does not ever become true, but if test (SELECT * FROM [dbo].[myData] WHERE [ID] = #Id) with a the matching UID it comes back with data.
This statement is problematic,,
DECLARE #tAudit table (id uniqueidentifier)
IF EXISTS(SELECT * FROM [dbo].[myData] WHERE [ID] = #Id)
-- UPDATE
BEGIN
#id is an Output Parameter and is null by default and you are trying to check that..
basically NEWID() won't be duplicated,so update part is redundant
How are you declaring the parameter in your code? Is it ParameterDirection.Output?
Try changing it to ParameterDirection.InputOutput. Your SQL looks okay. And you can pass an input value to a parameter declared as OUTPUT in your stored procedure. So maybe it's just that ParameterDirection.
You can also change this
IF EXISTS(SELECT * FROM [dbo].[myData] WHERE [ID] = #Id)
to
IF #Id IS NOT NULL AND EXISTS(SELECT * FROM [dbo].[myData] WHERE [ID] = #Id)
If your ID column isn't nullable then it's going to work the same either way. But this is a little more explicit, showing that it's recognized that #Id might be null because it's an OUTPUT parameter.
This is my fix.
This is my new stored procedure
ALTER PROCEDURE [dbo].[spInsertUpdatemyData]
#ID uniqueidentifier,
#IDOut uniqueidentifier OUTPUT,
#CONTENT nvarchar(255)
AS
BEGIN
--SET NOCOUNT ON;
DECLARE #tAudit table (outputID uniqueidentifier)
IF EXISTS(SELECT * FROM [dbo].[myData] WHERE [ID] = #ID)
-- UPDATE
BEGIN
UPDATE [dbo].[CBData]
SET [ID] = #ID,
[Content] = #Content
OUTPUT inserted.[ID] INTO #tAudit
WHERE [ID] = #ID
SELECT outputID FROM #tAudit;
END
ELSE
BEGIN
-- INSERT
INSERT INTO [dbo].myData
([ID],[Content])
OUTPUT inserted.[ID] INTO #tAudit
VALUES(NEWID(),#Content);
SELECT outputID FROM #tAudit
END;
set #IDOut = (SELECT outputID FROM #tAudit);
END
and the relative C#
//Add Parameter for output to sql command then Change Direction of parameter
cmd.Parameters.Add("#IDOut", SqlDbType.UniqueIdentifier).Value = Guid.Empty ;
cmd.Parameters["#IDOut"].Direction = ParameterDirection.InputOutput;
cmd.ExecuteNonQuery();
currentRecord.ID = Guid.Parse(cmd.Parameters["#IDOut"].Value.ToString());
cmd.Transaction.Commit();
I have a table 'Agent' its ID is already inserted before and displayed in a textbox for using it in my insertion , now I try just to add the rest of records but in couldn't do that an error is displayed ...(I'm working in asp with c#) and SQL SERVER :
Violation of PRIMARY KEY constraint 'PK__Agent. "Can not insert duplicate key in object 'dbo.Agent. "The duplicate key value is (1).
The statement has been terminated.
this my code behind :
protected void Button_validerinfo_Click(object sender, EventArgs e)
{
try
{
c.cmd = c.cn.CreateCommand();
c.cmd.CommandText = "AjouterAgent";
c.cmd.CommandType = CommandType.StoredProcedure;
if (c.cn.State == ConnectionState.Closed)
{
c.cn.Open();
}
c.cmd.Parameters.Add("#ppr", SqlDbType.Int);
c.cmd.Parameters.Add("#lieu", SqlDbType.VarChar);
c.cmd.Parameters.Add("#adresspro", SqlDbType.VarChar);
c.cmd.Parameters.Add("#adressperso", SqlDbType.VarChar);
c.cmd.Parameters.Add("#telbureau", SqlDbType.VarChar);
c.cmd.Parameters.Add("#telgsm", SqlDbType.VarChar);
c.cmd.Parameters.Add("#email", SqlDbType.VarChar);
c.cmd.Parameters.Add("#np", SqlDbType.VarChar);
c.cmd.Parameters.Add("#proff", SqlDbType.VarChar);
c.cmd.Parameters.Add("#empl", SqlDbType.VarChar);
c.cmd.Parameters.Add("#retraite", SqlDbType.VarChar);
c.cmd.Parameters.Add("#TypeOperation", SqlDbType.Int);
c.cmd.Parameters["#ppr"].Value = TextBox_PPR.Text;
c.cmd.Parameters["#lieu"].Value = TextBox_ln.Text;
c.cmd.Parameters["#adresspro"].Value = TextBox_adrspro.Text;
c.cmd.Parameters["#adressperso"].Value = TextBox_adrssperso.Text;
c.cmd.Parameters["#telbureau"].Value = TextBox_bureau.Text;
c.cmd.Parameters["#telgsm"].Value = TextBox_gsm.Text;
c.cmd.Parameters["#email"].Value = TextBox_email.Text;
c.cmd.Parameters["#np"].Value = TextBox_npconj.Text;
c.cmd.Parameters["#proff"].Value = TextBox_prof.Text;
c.cmd.Parameters["#empl"].Value = TextBox_empl.Text;
c.cmd.Parameters["#retraite"].Value = DropDownList_retraite.SelectedValue;
c.cmd.Parameters["#TypeOperation"].Value = 0;
c.cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
finally
{
if (c.cn.State == ConnectionState.Open)
{
c.cn.Close();
}
}
}
and my stroredprocedure :
USE [CVtech]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[AjouterAgent]
#ppr int,
#lieu varchar(100),
#adresspro varchar(100),
#adressperso varchar(100),
#telbureau varchar(100),
#telgsm varchar(100),
#email varchar(100),
#np varchar(100),
#proff varchar(100),
#empl varchar(100),
#retraite varchar(3),
#TypeOperation nvarchar(1)
as
if(#TypeOperation = '0')
begin tran
if exists ( select ppr from Agent where PPR = #ppr)
begin
insert into Agent (LieuNaissance,AdressePro, AdressePerso,TelBureau,TelPerso,Email)
values (#lieu,#adresspro, #adressperso,#telbureau,#telgsm,#email)
end
insert into Conjoint (PPR,NomPrenom , Profession, Employeur, Retraite) values (#ppr ,#np ,#proff,#empl,#retraite)
commit
Does your table have Identity Specification switched to off? To check go on your table, right click, design, select the primary key, in the options displayed you should see IDENTITY SPECIFICATION. This must be set to yes in your case. For more information about this, you can view this link from MSDN : http://msdn.microsoft.com/en-us/library/x5s13zy2.aspx
Obviously, if you want to do an update, you must execute an update statement, and not insert the same record again.
Yes, first my question is, are you send the column value (which one has primary key constrain) from user? if no mean check that column has the identity or not(if no mean change it) if yes then you have to pass the unique value for that textbox
USE [CVtech]
GO
/****** Object: StoredProcedure [dbo].[AjouterAgent] Script Date: 02/04/2014 12:00:08 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[AjouterAgent]
#ppr int,
#lieu varchar(100),
#adresspro varchar(100),
#adressperso varchar(100),
#telbureau varchar(100),
#telgsm varchar(100),
#email varchar(100),
#np varchar(100),
#proff varchar(100),
#empl varchar(100),
#retraite varchar(3),
#TypeOperation nvarchar(1)
as
if(#TypeOperation = '0')
begin tran
if exists ( select ppr from Agent where PPR = #ppr)
begin
update Agent set LieuNaissance=#lieu,AdressePro=#adresspro, AdressePerso=#adressperso , TelBureau=#telbureau,TelPerso=#telgsm,Email=#email
where PPR = #ppr
end
if exists ( select ppr from Agent where PPR = #ppr)
begin
update Conjoint set PPR=#ppr,NomPrenom =#np, Profession=#proff, Employeur=#empl, Retraite=#retraite where ppr= #ppr
end
else
insert into Conjoint (PPR,NomPrenom , Profession, Employeur, Retraite) values (#ppr ,#np ,#proff,#empl,#retraite)
commit
So the code would be this:
ALTER proc [dbo].[AjouterAgent]
#ppr int,
#lieu varchar(100),
#adresspro varchar(100),
#adressperso varchar(100),
#telbureau varchar(100),
#telgsm varchar(100),
#email varchar(100),
#np varchar(100),
#proff varchar(100),
#empl varchar(100),
#retraite varchar(3),
#TypeOperation nvarchar(1)
as
if(#TypeOperation = '0')
begin tran
if exists ( select ppr from Agent where PPR = #ppr)
begin
UPDATE Agent
SET LieuNaissance = #lieu
,AdressePro = #adresspro
,AdressePerso = #adressperso
,TelBureau = #telbureau
,TelPerso = #telgsm
,Email = #email
WHERE ppr = #ppr
end
insert into Conjoint (PPR,NomPrenom , Profession, Employeur, Retraite) values (#ppr ,#np ,#proff,#empl,#retraite)
commit
It doesn't seem to make sense that you are trying to do an insert where some value in Agent exists.
if exists ( select ppr from Agent where PPR = #ppr)
begin
insert into Agent (LieuNaissance,AdressePro, AdressePerso,TelBureau,TelPerso,Email)
values (#lieu,#adresspro, #adressperso,#telbureau,#telgsm,#email)
end
I would expect that if the item exists that you want to do an UPDATE not an INSERT.
I have a table that accepts a bunch of parameters and saves it as a new contact through a stored procedure using an INSERT INTO statement. For some reason I get a SqlException when some of my parameters are left null. All of the parameters left null are indeed nullable in the SQL Server table, so I don't understand the issue. My thoughts are that my INSERT statement is accepting all the parameters even if they are null and trying to insert them into my table, which I believe is a syntactical "no-no"
Anyway, here is the C# code:
try
{
using (SqlConnection sqlConn = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("Insert_NewContact", sqlConn))
{
sqlConn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#CompanyID", CompanyID);
cmd.Parameters.AddWithValue("#email", email);
cmd.Parameters.AddWithValue("#phone", phone);
cmd.Parameters.AddWithValue("#fax", fax);
cmd.Parameters.AddWithValue("#fName", fName);
cmd.Parameters.AddWithValue("#lName", lName);
cmd.Parameters.AddWithValue("#sendVia", sendVia);
cmd.Parameters.AddWithValue("#default", defaultContact);
cmd.Parameters.AddWithValue("#repo", repo);
cmd.Parameters.AddWithValue("#fail", fail);
cmd.Parameters.AddWithValue("#borrow", borrow);
cmd.Parameters.AddWithValue("#loan", loan);
cmd.ExecuteNonQuery();
sqlConn.Close();
}
}
}
catch (Exception e)
{
throw e;
}
and here is the stored procedure in SQL:
ALTER PROCEDURE [dbo].[Insert_NewContact]
#CompanyID INT,
#email VARCHAR(50),
#phone VARCHAR(50),
#fax VARCHAR(50),
#fName VARCHAR(50),
#lName VARCHAR(50),
#sendVia VARCHAR(50),
#default BIT,
#repo TINYINT,
#fail TINYINT,
#borrow TINYINT,
#loan TINYINT
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
INSERT INTO Master_Contacts(
companyID,
fName,
lName,
phone,
email,
fax,
send_via,
defaultcontact,
repoRole,
borrowRole,
failRole,
loanRole
)
VALUES (
#CompanyID,
#fName,
#lName,
#phone,
#email,
#fax,
#sendVia,
#default,
#repo,
#borrow,
#fail,
#loan
)
END TRY
Not sure why the AS BEGIN and NOCOUNT are so weird, but they are correct in the Stored Proc.
Anyway, if I leave the email, phone, fax, etc. empty in my application, I get this error:
SqlException was unhandled by user code
Procedure or function 'Insert_NewContact' expects parameter '#email', which was not supplied.
How can I edit my stored proc to make it work with null values?
Set the default value for the parameter as null, try this:
#CompanyID INT,
#email VARCHAR(50) = null,
#phone VARCHAR(50) = null,
#fax VARCHAR(50) = null,
#fName VARCHAR(50) = null,
#lName VARCHAR(50),
#sendVia VARCHAR(50),
#default BIT,
#repo TINYINT,
#fail TINYINT,
#borrow TINYINT,
#loan TINYINT
You should pass DBNull.Value when you have a null value. For example.
cmd.Parameters.AddWithValue("#email", email == null ? DBNull.Value : (object)email);
ALTER PROCEDURE [dbo].[Insert_NewContact]
#CompanyID INT,
#email VARCHAR(50) = null,
#phone VARCHAR(50) = null,
#fax VARCHAR(50) = null,
#fName VARCHAR(50) = null,
#lName VARCHAR(50) = null,
#sendVia VARCHAR(50) = null,
#default BIT = 0,
#repo TINYINT = 0,
#fail TINYINT = 0,
#borrow TINYINT = 0,
#loan TINYINT = 0
AS
BEGIN
SET NOCOUNT ON;
BEGIN TRY
INSERT INTO Master_Contacts(
companyID,
fName,
lName,
phone,
email,
fax,
send_via,
defaultcontact,
repoRole,
borrowRole,
failRole,
loanRole
)
VALUES (
#CompanyID,
#fName,
#lName,
#phone,
#email,
#fax,
#sendVia,
#default,
#repo,
#borrow,
#fail,
#loan
)
END TRY
UPDATE: my code is behaving as expected by there was a typo in the stored procedure that was the reason it was failing.
I can't seem to figure out why or how to fix this because I am not getting any errors what I am getting is the return value is 0 which means fail.
Here is my .net code:
SqlParameter returnValue= new SqlParameter("returnValue", SqlDbType.Int);
returnValue.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(returnValue);
cmd.ExecuteNonQuery();
result = Convert.ToInt32(returnValue.Value); //1 success and 0 failed
My stored procedure:
CREATE PROCEDURE EmployeeUpdate
#employee_id BIGINT,
#name nvarchar(250)
AS
BEGIN
SET NOCOUNT ON
DECLARE #Result int
SET #Result = 0
UPDATE Employee
SET name = #name
WHERE employee_id = #employee_id
IF (##rowcount = 1)
BEGIN
SET #Result = 1
END
SET NOCOUNT OFF
RETURN #Result
END
So if I just execute the stored procedure from SQL Server Management Studio, it does update my row successfully without any error
EXEC EmployeeUpdate 34,'John John'
Return Value = 1
Replace the following
CREATE PROCEDURE EmployeeUpdate
#employee_id BIGINT,
#name nvarchar(250)
AS
BEGIN
SET NOCOUNT ON
With Following
CREATE PROCEDURE EmployeeUpdate
#employee_id BIGINT,
#name nvarchar(250)
AS
BEGIN
SET NOCOUNT OFF
SET NOCOUNT ON is indicating that number of rows effect by T-SQL will
not be returned
SET NOCOUNT OFF mean that number of rows effect by
T-SQL will be returned.
I would suggest to remove returnValue parameter altogether and just use the return value of ExecuteNonQuery() method instead:
int rowsAffected = cmd.ExecuteNonQuery();
result = rowsAffected == 1 ? 1 : 0;
Stored procedure:
CREATE PROCEDURE EmployeeUpdate
#employee_id BIGINT,
#name nvarchar(250)
AS
BEGIN
UPDATE Employee
SET name = #name
WHERE employee_id = #employee_id
END