为了账号安全,请及时绑定邮箱和手机立即绑定

怎么用ASP.NET MVC用Entity调用带有返回值的存储过程?

怎么用ASP.NET MVC用Entity调用带有返回值的存储过程?

子衿沉夜 2018-12-06 11:14:37
bnde是实例化Entity, proc_LogOn是登陆的存储过程 bnsde.proc_LogOn(username, HashPassword, ”这里会显示要输入第三个参数,应该输入什么?“);   存储过程如下: ALTER PROCEDURE [dbo].[proc_LogOn] -- Add the parameters for the stored procedure here @username varchar(50), @password varchar(50), @result bit output -- 如果结果不为0则登录成功,否则登录失败ASif exists(select * from users where username=@username and password=@password) begin set @result = 1 -- 登录成功 endelse begin set @result = 0 -- 登录失败 end  求解~
查看完整描述

1 回答

?
喵喔喔

TA贡献1735条经验 获得超5个赞

只要照着下面代码中的para3改为你的result1/2就可以了。

            using (SEntities se = new SEntities())
{
EntityConnection entityConnection = (EntityConnection)se.Connection;
DbConnection storeConnection = entityConnection.StoreConnection;

storeConnection.Open();

DbCommand command = storeConnection.CreateCommand();
command.CommandText = "NameOfStoredProcedure";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(new SqlParameter("param1", value_of_param1));
command.Parameters.Add(new SqlParameter("param2", value_of_param2));

SqlParameter param3 = new SqlParameter();
pA.SqlDbType = SqlDbType.Bit;
pA.ParameterName = "@param3";
pA.Direction = ParameterDirection.Output;
command.Parameters.Add(param3);

command.ExecuteNonQuery();

returnValue = Convert.ToBoolean(param3.Value);
}
查看完整回答
反对 回复 2019-01-21
  • 1 回答
  • 0 关注
  • 275 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信