存储过程是正确的,我已经在查询分析器里试过了
出现错误:
过程 'sp' 需要参数 '@mc',但未提供该参数SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "sp";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter mc2 = new SqlParameter("@mc",SqlDbType.VarChar,50);
mc2.Direction = ParameterDirection.Input ;
mc2.Value = "bahezhe";
cmd.Parameters.Add(mc2);
SqlParameter pass2 = new SqlParameter("@pass", SqlDbType.VarChar);
pass2.Direction = ParameterDirection.Input ;
pass2.Value = "bahezhe";
cmd.Parameters.Add(pass2);
SqlParameter find = new SqlParameter("@find", SqlDbType.Int );
find.Direction = ParameterDirection.Output ;
md.Parameters.Add(find);
cmd.ExecuteNonQuery ()
this.TextBox1.Text=find.Value.ToString();
出现错误:
过程 'sp' 需要参数 '@mc',但未提供该参数SqlCommand cmd = new SqlCommand();
cmd.Connection = cn;
cmd.CommandText = "sp";
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter mc2 = new SqlParameter("@mc",SqlDbType.VarChar,50);
mc2.Direction = ParameterDirection.Input ;
mc2.Value = "bahezhe";
cmd.Parameters.Add(mc2);
SqlParameter pass2 = new SqlParameter("@pass", SqlDbType.VarChar);
pass2.Direction = ParameterDirection.Input ;
pass2.Value = "bahezhe";
cmd.Parameters.Add(pass2);
SqlParameter find = new SqlParameter("@find", SqlDbType.Int );
find.Direction = ParameterDirection.Output ;
md.Parameters.Add(find);
cmd.ExecuteNonQuery ()
this.TextBox1.Text=find.Value.ToString();
create proc sp
@mc varchar(50),
@pass varchar(50),
@find int output
as
declare @num int
select @num=count(*) from jinshi_user_all where ByName=@mc and pwd=@pass
if @num>0
set @find=1
else
set @find=0
go
/// <summary>
/// 执行存过
/// </summary>
/// <param name="procName">存过名称</param>
/// <param name="Paras">参数</param>
public void ExecProc(string procName, params object[] Paras)
{
SqlConnection m_Conn = new SqlConnection("...");
m_Conn.Open(); SqlCommand CMD = new SqlCommand(procName, m_Conn);
CMD.CommandType = CommandType.StoredProcedure;
SqlCommandBuilder.DeriveParameters(CMD);//第一个参数为@return
for (int i = 1; i < CMD.Parameters.Count; i++)
{
CMD.Parameters[i].Value = Paras[i - 1];
} CMD.ExecuteNonQuery();
for (int i = 1; i < CMD.Parameters.Count; i++)
{
Paras[i - 1] = CMD.Parameters[i].Value;
} m_Conn.Close();
}