日期:2014-05-17  浏览次数:20536 次

asp.net参数化操作数据库,为什么SqlParameter只能用一次?
            string id = context.Request["BRS_id"].ToString();//取用户输入的用户名
            string password = FormsAuthentication.HashPasswordForStoringInConfigFile(context.Request["BRS_password"].ToString(), "MD5");//取用户输入的密码并加密            SqlParameter[] sp = new SqlParameter[]
            {
                new SqlParameter("@id",SqlDbType.VarChar),
                new SqlParameter("@password",SqlDbType.VarChar)
            };
            sp[0].Value = id;
            sp[1].Value = password;
            SqlDataReader dr = SQLHelper.ExecuteReader("SELECT lock FROM users WHERE id = @id", CommandType.Text, sp);//这里可以正常读到
            if (dr.Read())
            {
                if (int.Parse(dr[0].ToString()) >= 3)//检测用户锁状态
                    context.Response.Write("LOCKED");
                else
                {
                    dr = SQLHelper.ExecuteReader("SELECT name,department,role,verification FROM users WHERE id = @id and password = @password", CommandType.Text, sp);//卡在这里过不去
                    if (dr.Read())
                    {
                        if (dr[3].ToString() != auth.ToLower())//验证用户终端
                            context.Response.Write("FF");
                        else
                        {
.......
.........
............