首页 新闻 会员 周边

参考这个方法写一个 查询!

0
[已解决问题] 解决于 2012-09-24 14:01

   public static int ValidateUserInfo(string userName, string userPwd)
        {
            SqlDataReader tablePws = null;
            string md5pws = ToMD5(userPwd);

            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = staticValue.staticValue.userDB;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;

            cmd.CommandText = string.Format("select password,Id from u_users where (LoginName='{0}' or handphone='{2}' or eMail='{3}')", userName);
            conn.Open();
            tablePws = cmd.ExecuteReader();
            cmd.Dispose();
            conn.Close();
            conn.Dispose();

            if (tablePws == null)
            {
                return -1;
            }
            else
            {
                string key = Encoding.Unicode.GetString(tablePws["password"] as byte[]);
                if (md5pws == Decrypt(key))
                {
                    int userId = 0;
                    int.TryParse(tablePws["Id"].ToString(), out userId);
                    return userId;
                }
                return -1;
            }
        }

姓名 ID 等等

水嫩小白菜的主页 水嫩小白菜 | 初学一级 | 园豆:3
提问于:2012-09-20 13:56
< >
分享
最佳答案
0

cmd.CommandText = string.Format("select password,Id from u_users where (LoginName='{0}' or handphone='{2}' or eMail='{3}')", userName);

你没有写入{1} 就直接从0-》2了,应该有错的。

奖励园豆:5
chenping2008 | 大侠五级 |园豆:9836 | 2012-09-20 17:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册