Search code examples
c#sql-serverasp.net-mvc-5telerik-mvctelerik-open-access

SP Executed Successfully But Data Not Updated


I am using Telerik Open Access for interaction with MSSQL SERVER 2012.

I have made a stored procedure which will set IsActive column of Role Table to 0(false) and return all data of Role where IsActive= 1 (True)

My Role table has columns:

RoleId(int), RoleName(varchar(50)), AliasName(varchar(50)), IsActive(bit).

My Stored Procedure:

ALTER PROCEDURE [SPDeleteRole]
@Role_Id int
AS
BEGIN
  UPDATE [Role] SET IsActive = 0 WHERE RoleId = @Role_Id
  Select * from [Role] WHERE IsActive = 1 ORDER BY RoleName
END

I call this SP in my application like below:

public List<RoleDTO> DeleteRole(int roleId)
{
  OAParameter oaParameter = new OAParameter();
  oaParameter.ParameterName = "Role_Id";
  oaParameter.DbType = System.Data.DbType.Int32;
  oaParameter.Value = roleId;
  List<RoleDTO> roleList = base.ExecWithStoreProcedureGetDataWithParam("SPDeleteRole", oaParameter);
  return AutoMapper.Mapper.Map<List<RoleDTO>>(roleList);
}

public List<T> ExecWithStoreProcedureGetDataWithParam(string query, OAParameter parameters)
{
  var queryResult = dbContext.ExecuteQuery<T>(query, CommandType.StoredProcedure, parameters);
  dbContext.Dispose();
  return queryResult.ToList();
}

Now my problem is this works fine. But when I refresh the page, the role which I inactivated comes to in the list.

I checked through debugging that list comes from SP is exactly of Active Roles. But as soon as I refresh the page the role inactivated roles comes again in the list. I have verified SP by executing it in MSSQL SERVER and it works fine.

Issue:

enter image description here


Solution

  • May be you should write dbContext.SaveChanges() before you dispose the dbcontext?