using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace ConsoleApplication2
{
class Program
{
private const string strconn = "Data Source=.;Initial Catalog=MySchool;Integrated Security=True";
static void Main(string[] args)
{
Program p=new Program();
string name="admin";
string pass="0";
bool b= p.CheckUserInfo(name,pass);
if(b)
{
Console.WriteLine("成功");
}
else
{
Console.WriteLine("登录失败!");
}
Console.ReadLine();
}
public bool CheckUserInfo(string Name, string pwd)
{
SqlConnection conn = new SqlConnection(strconn);
try
{
string strSql = "select count(*) from Admin where LoginId='"+Name+"'and LoginPwd='"+pwd+"'";
conn.Open();
SqlCommand comm = new SqlCommand(strSql, conn);
int iRet = (int)comm.ExecuteScalar();
if(iRet>0){
Console.WriteLine(strSql);
return true;
}
}
catch (Exception ex)
{
Console.WriteLine("错了"+ex.Message);
}
finally
{
conn.Close();
}
return false;
}
}
}
数据库第十四章示例3
最新推荐文章于 2021-01-28 01:01:28 发布