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

求大神帮忙看看这这问题
 Console.WriteLine("请输入用户名:");
            string name=Console.ReadLine();
            Console.WriteLine("请输入密码");
            string wpassword = Console.ReadLine();
            using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDBFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"))
            {
                conn.Open();
                using(SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = "select * from User where name='"+name+"'";
                    using(SqlDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.Read())
                        {
                            //用户存在
                            string password = reader.GetString(reader.GetOrdinal("password"));
                            if (wpassword == password)
                            {
                                Console.WriteLine("登录成功");
                            }
                            else 
                            {
                                Console.WriteLine("密码错误");
                            }
 &