首页 新闻 赞助 找找看

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

0
悬赏园豆:5 [已解决问题] 解决于 2011-10-30 16:25

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则登录成功,否则登录失败
AS
if exists(select * from users where username=@username and password=@password)
begin
set @result = 1 -- 登录成功
end
else
begin
set @result = 0 -- 登录失败
end


 求解~

lizongshen1990的主页 lizongshen1990 | 初学一级 | 园豆:5
提问于:2011-10-29 12:28
< >
分享
最佳答案
0

只要照着下面代码中的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);
}
收获园豆:5
today4king | 老鸟四级 |园豆:3499 | 2011-10-30 14:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册