请问各位大侠,在使用Command命令时,如果不用存储过程,则能很容易的得到正确答案,但是如果使用存储过程的话,就无法得到正确答案,请问各位这是什么问题啊?
======
语句:string checkUser="select count(*) from adminuser where username='"+this.TextBox1.Text+"' and userpass='"+this.TextBox2.Text+"'";
SqlCommand cmd=new SqlCommand(checkUser,conn);
conn.Open();
int i=Convert.ToInt32(cmd.ExecuteScalar());
这样是可以得到正确答案的,i=1
===========
存储过程:
create proc checkUser @pwd varchar(20) ,@uid varchar(20)
as
select count(*) from adminuser where username='@uid' and userpass='@pwd'
go
对应的语句是:
SqlCommand cmd=new SqlCommand("checkUser",conn);
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@pwd",SqlDbType.VarChar,20));
cmd.Parameters["@pwd"].Value=this.TextBox2.Text;
cmd.Parameters.Add(new SqlParameter("@uid",SqlDbType.VarChar,20));
cmd.Parameters["@uid"].Value=this.TextBox1.Text;
conn.Open();
int i=Convert.ToInt32(cmd.ExecuteScalar());
这样做就无法得到正确答案,i=0
**********************
请问这是为什么啊?急!

解决方案 »

  1.   

    select count(*) from adminuser where username=@uid and userpass=@pwd
      

  2.   

    存储过程:
    create proc checkUser @pwd varchar(20) ,@uid varchar(20)
    as
    select count(*) from adminuser where username=@uid and userpass=@pwd
    go
      

  3.   

    string checkUser="select count(*) from adminuser where username='"+this.TextBox1.Text+"' and userpass='"+this.TextBox2.Text+"'";
    SqlCommand cmd=new SqlCommand(checkUser,conn);没看明白你这几句的意思!!!checkUser和username有关系吗?
      

  4.   

    select count(*) from adminuser where username='@uid' and userpass='@pwd'存储过程中不需要单引号,去处了就行!!!