Sql 在ASP.NET MVC中更新存储过程
我尝试使用存储过程更改用户密码 控制器:Sql 在ASP.NET MVC中更新存储过程,sql,asp.net-mvc,stored-procedures,Sql,Asp.net Mvc,Stored Procedures,我尝试使用存储过程更改用户密码 控制器: public ActionResult ChangeMyPassword(MyModel model) { int UserId = Convert.ToInt32(Session["UserId"]); context.sp_ChangePassword(UserId, model.NewPassword); context.SaveChanges(); return view(); } USE [CRM_DEMO]
public ActionResult ChangeMyPassword(MyModel model)
{
int UserId = Convert.ToInt32(Session["UserId"]);
context.sp_ChangePassword(UserId, model.NewPassword);
context.SaveChanges();
return view();
}
USE [CRM_DEMO]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_ChangePassword]
@Id int ,
@NewPassword Varchar(50)
AS
Update UserTable
set
UserPassword = @NewPassword
WHERE UserId= @Id
存储过程:
public ActionResult ChangeMyPassword(MyModel model)
{
int UserId = Convert.ToInt32(Session["UserId"]);
context.sp_ChangePassword(UserId, model.NewPassword);
context.SaveChanges();
return view();
}
USE [CRM_DEMO]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_ChangePassword]
@Id int ,
@NewPassword Varchar(50)
AS
Update UserTable
set
UserPassword = @NewPassword
WHERE UserId= @Id
它起作用了;但是,数据库中的密码不会更改。我遗漏了什么?我在密钥用户ID中看到一个空格
int UserId = Convert.ToInt32(Session["UserId "]);
^
您是否可以验证是否实际将userid值传递给存储过程。如果不更新,则不会更新,并且不更新行也不会出错。尝试此操作
USE [CRM_DEMO]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[sp_ChangePassword]
(
@Id int ,
@NewPassword Varchar(50)
)
AS
BEGIN
UPDATE UserTable
SET UserPassword = @NewPassword
WHERE UserId= @Id
END
嗯,我看不出还有什么问题。您能否快速停止“context.sp_ChangePassword(UserId,model.NewPassword)”并检查这两个值?İ认为问题出在数据库端。控制器端没有问题。然后从数据库调用该过程,看看它是否有效。