Hi
I have below code but data is not getting updated.Neither i am getting any error message
try
{
using (SqlConnection con = new SqlConnection(Common.CommonFunction.cnn_Live))
{
SqlCommand cmd = new SqlCommand("Sp_Department", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@EntryNo", SqlDbType.Int).Value = hdfDeleteID.Value;
cmd.Parameters.Add("@Action", SqlDbType.NVarChar).Value = "D";
con.Open();
cmd.ExecuteNonQuery();
string message = Common.CommonFunction.recordDeletedSucessfully;
ShowMessage("Success", "Record Saved Successfully", "Success");
GetData();
}
}
catch (Exception ex)
{
ShowMessage("Oops...", ex.Message, "error");
}
Stored Procedure
PROCEDURE [dbo].[sp_Department]
@Action VARCHAR(1)
,@EntryNo int = Null
,@Description VARCHAR(50) = NULL
,@ShortName VARCHAR(25) = NULL
AS
BEGIN
SET NOCOUNT ON;
--UPDATE
IF @Action = 'U'
BEGIN
UPDATE dbo.Department
SET Description = @Description, updatedon = GETDATE() WHERE docentry = @EntryNo
END
--DELETE
IF @Action = 'D'
BEGIN
UPDATE dbo.Department
SET status = 0 , updatedon = GETDATE() WHERE docentry = @EntryNo
END
END
Thanks
David MaddenPosted Aug 17, 2024, 1:53 PM
Check your line of code during execution in Debug to see if hdfDeleteID does have value, then, after stepping over that line, check Parameters to see if the expected entry is there and have the expected value. It is like that @EntryNo is not getting a value as expected and taking NULL as the value.
Ramco RamcoPosted Aug 17, 2024, 8:27 AM
Hi Gowtham
I want to update only. I don't want to delete record.
Currently it is not updating
Thanks
Gowtham CpPosted Aug 17, 2024, 7:44 AM
Hello Ramco Ramco ,
Issue: The
DELETEblock was incorrectly using anUPDATEstatement to set the status to0instead of removing the record.Corrected Code: