using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace shang_ji
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
string name="";
string pwd="";
p.login(ref name,ref pwd);
bool b=p.check(name,pwd);
if (b)
{
Console.WriteLine("登陆成功");
p.Login();
}
else {
Console.WriteLine("登陆无效");
}
Console.ReadLine();
}
public void login(ref string name,ref string pwd) {
Console.WriteLine("请输入用户名:");
name = Console.ReadLine();
Console.WriteLine("请输入密码:");
pwd = Console.ReadLine();
}
public bool check(string x,string y) {
string s = "Data Source=.;Initial Catalog=MySchool;Integrated Security=True";
SqlConnection a = new SqlConnection(s);
a.Open();
string i = "select count(*) from Admin where LoginId='"+x+"'and LoginPwd='"+y+"'";
SqlCommand c = new SqlCommand(i,a);
int b = (int)c.ExecuteScalar();
try
{
if (b != 0)
{
return true;
}
return false;
}
catch (Exception)
{
Console.WriteLine("运行错误");
return false;
}
finally {
a.Close();
}
}
public void Login() {
bool z=true;
do{
Console.WriteLine("========&
ACCP S1 C#第十四章 第十五章 上机练习
最新推荐文章于 2019-12-24 22:43:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)