学习Unity3D之登陆。

来源:互联网 发布:linux tail f 编辑:程序博客网 时间:2024/04/28 22:27

欢迎来到unity学习unity培训unity企业培训教育专区,这里有很多U3D资源U3D培训视频U3D教程U3D常见问题U3D项目源码,我们致力于打造业内unity3d培训、学习第一品牌。

建立类方法:

public Student Login(string name, string password)
       {
           List<Student> list = new List<Student>();
           Student s = new Student();
           SqlConnection con = DB.Connect();
           con.Open();
           string sql = "select * from student where name='" + name + "' and password='" + password + "'";
           SqlCommand com = new SqlCommand(sql, con);
           SqlDataReader reader = com.ExecuteReader();
           while (reader.Read())
           {
               Student s2 = new Student();
               s2.Id = (int)reader.GetValue(0);
               s2.Name = (string)reader.GetValue(1);
               s2.Password = (string)reader.GetValue(2);
               list.Add(s2);
           }
           foreach (Student s3 in list)
           {
               s = s3;
           }
           DB.Close(con, reader);
           return s;
       }

在主方法中引用:

       Console.WriteLine("请输入姓名:");
       string name = Console.ReadLine();
       Console.WriteLine("请输入密码:");
       string password = Console.ReadLine();
       Student s = new Student().Login(name, password);
       if (s.Name != null)
       {
           Console.WriteLine("登陆成功!");
           ChooseList();
       }
       else {
           Console.WriteLine("登录失败,请重新输入!");
           Input();
       }

0 0
原创粉丝点击