日期:2014-05-18  浏览次数:20828 次

参数赋值
namespace TdrSys_yh.SQLserverDAL
{
  public class SQLTdrSys_yh : ITdrSys_yh
  {
  private const string SQL_SELECT_USER = "select count(*) from Users where username=@name and password=@password";

  public int existJud(string uname, string upassword) 
  {
   
   
  }

  }
}
在函数里我怎样将用户输入的用户名和密码赋值给@name和@password

------解决方案--------------------
C# code

SqlParameter[] parameters = {new SqlParameter("@name", SqlDbType.VarChar,40),
                    new SqlParameter("@password", SqlDbType.VarChar,100)};
            parameters[0].Value = "";//赋值@NAME
            parameters[1].Value = "";//赋值@PASSWORD

SqlCommand cmd = new SqlCommand();

//后边执行的语句不写了。。。累

------解决方案--------------------
public int existJud(string uname, string upassword)
{
SqlConnection cn=new SqlConnection("连接字符串");
SqlCommand cmd=new SqlCommand(SQL_SELECT_USER,cn);
cmd.Parameters.AddWithValue("@name",uname);
cmd.Parameters.AddWithValue("@password",upassword);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();

}