当前位置: 代码迷 >> Sql Server >> 求大神帮忙看看这这有关问题
  详细解决方案

求大神帮忙看看这这有关问题

热度:10   发布时间:2016-04-24 21:41:03.0
求大神帮忙看看这这问题
 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("密码错误");
                            }
                        }
  相关解决方案