Procedure or function 'login' expects parameter '@Abc', which was not supplied
4 小时搜索和尝试但没有用我已经提供了这个参数(复制/粘贴)并且给过程的参数数量与过程相同并且顺序相同。
@Abc 是一个输出参数。
存储过程定义:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER proc [dbo].[login]
(
@Abc int output,
@firstname varchar(255) output,
@lastname varchar(255) output,
@Email varchar(255),
@pass varchar(255)
)
As
begin
if not exists (select Email from user_1 where email=@email)
select @Abc = 0
else begin
if not exists (
select Email from user_1 where email =@Email and password = @pass
)
select @Abc = 1
else
select @Abc = 2,@firstname = u.first_name ,@lastname=u.last_name from user_1 u where u.email = @email
end
end
调用存储过程的代码:
myCon.Open();
TextBox username = UserName;
TextBox password = Password;
SqlCommand myCommand = new SqlCommand("login", myCon);
SqlParameter count= myCommand.Parameters.Add("@Abc", SqlDbType.Int);
count.Direction = ParameterDirection.Output;
SqlParameter fnp = myCommand.Parameters.Add("@firstname", SqlDbType.VarChar,255);
fnp.Direction = ParameterDirection.Output;
SqlParameter lnp = myCommand.Parameters.Add("@lastname", SqlDbType.VarChar, 255);
lnp.Direction = ParameterDirection.Output;
myCommand.Parameters.AddWithValue("@Email",username.Text);
myCommand.Parameters.AddWithValue("@pass", password.Text);
myCommand.ExecuteNonQuery();
myCon.Close();
最佳答案
你遗漏了:
myCommand.CommandType = CommandType.StoredProcedure;
因此发送到数据库的命令是错误的 sp_executeSQL
调用而不是所需的 exec login
仅供引用,还有一个更短的语法:
myCommand.Parameters.Add("@Abc", SqlDbType.Int).Direction = ParameterDirection.Output;
关于c# - 过程或函数需要未提供的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27188849/