c#小系统开发之登录 注册
来源:互联网 发布:spss数据统计与分析 编辑:程序博客网 时间:2024/04/30 12:25
欢迎来到unity脚本学习社区
今天来回顾一下控制台交互的登录与注册
一、注册(数据库的插入操作)
public int Registered (string name,string password,int age,string sex)
{
SqlConnection con = new SqlConnection("server=.;database=school;Trusted_Connection=SSPI");
con.Open();
SqlCommand com = new SqlCommand("insert into student (name,password,age,sex)values('"+name +"','"+password +"',"+age+",'"+sex+"')", con);
int i = com.ExecuteNonQuery();
con.Close();
return i;
}
二、登录(数据库查询操作)
public Student Login(string name,string password) {
Student s=new Student ();
SqlConnection con = new SqlConnection("server=.;database=school;Trusted_Connection=SSPI");
con.Open();
SqlCommand com = new SqlCommand("select name,password from student where name='" + name + "'and password='" + password + "'", con);
SqlDataReader re = com.ExecuteReader();
while (re.Read())
{
Student s1=new Student ();
s1.Name = (string)re.GetValue(0);
s1.password = (string)re.GetValue(1);
s = s1;
}
return s;
}
}
三、控制台界面(这里拿一个学生登录 注册来举例)
public void Student()
{
Console.WriteLine("*******************************************");
Console.WriteLine("*******************************************");
Console.WriteLine("************ 输入1 请登录 ***********");
Console.WriteLine("************ 输入2 请注册 ***********");
Console.WriteLine("*******************************************");
Console.WriteLine("*******************************************");
string a = Console.ReadLine();
switch (a)
{
case "1":
Console.WriteLine("输入学生姓名");
string name1 = Console.ReadLine();
Console.WriteLine("输入学生密码");
string password1 = Console.ReadLine();
s = new Student().Login(name1,password1 );
if (s.Name != null)
{
Console.WriteLine("登录成功");
StudentCourse();
}
else {
Console.WriteLine("登录失败 请重新登录");
}
break;
case "2":
Console.WriteLine("输入学生姓名");
string name = Console.ReadLine();
Console.WriteLine("输入学生密码");
string password = Console.ReadLine();
Console.WriteLine("输入学生年龄");
int age = int.Parse (Console.ReadLine());
Console.WriteLine("输入学生性别");
string sex = Console.ReadLine();
int i = new Student().Insert(name,password ,age,sex);
if (i == 1)
{
Console.WriteLine("注册成功");
Student();
}
else
{
Console.WriteLine("注册失败 请重新注册");
Student();
}
break;
default:
Console.WriteLine("请重新输入");
break;
}
}
0 0
- c#小系统开发之登录 注册
- Java开发之注册登录系统
- 小程序开发之登录
- android开发之登录&注册UI
- C#版2048---小圆脸图片版(登录与注册)
- 简单的注册登录展示小系统总结
- Java图形界面开发—简易登录注册小程序
- C#登录注册程序
- 系统登录注册模块
- 注册登录系统
- C#小项目之登录界面1
- web学习之博客小项目(登录注册模块)
- Struts2系列登录注册的小项目之验证规则
- django 个人博客系统开发 - 注册 登录 注销
- Struts 2.0 整合 Hibernate 3.2 开发注册登录系统
- 小型bbs论坛系统开发6 前台注册/登录页
- Django开发幼儿园管理系统---实现注册、登录功能
- 实验四 系统登录/注册模块(Android app)的开发
- UVa 10935 - Throwing cards away I
- 写作是一种爱好
- 模拟shell进程
- 项目笔记(物业管理系统)
- Git删除远程master分支问题
- c#小系统开发之登录 注册
- linux中Select 函数占用cpu过高问题
- 《深入浅出Windows Phone 8应用开发》之蓝牙编程
- 自己写简单的RobotFramework的Library
- ubuntu12.04 编译安装LLVM3.3,Clang和Libc++
- How to set mouse speed in X using xset or XF86Config
- 稀疏矩阵的三元组顺序表存储及矩阵相乘算法小结
- [水题][第一阶段-简单操作][HDOJ-2005]第几天?
- Remove Nth Node From End of List(从链表表尾删除第n个节点)