Layered, new third board layered
Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Data;
Using System. Data. SqlClient;
Using System. Configuration;
Using MySchoolModel;
Namespace MySchoolDAL
{
Public class Student
{
Public bool IsLogin (string name, string pwd)
{
Bool flag = false;
Try
{
String str = "data source =.; initial Catalog = MySchool; uid = sa; pwd = mnbv ";
SqlConnection conn = new SqlConnection (str );
Conn. Open ();
String SQL = "select count (1) from Admin where Name = '" + name + "' and Pwd = '" + pwd + "'";
SqlCommand cmd = new SqlCommand (SQL, conn );
Int num = Convert. ToInt32 (cmd. ExecuteScalar ());
If (num> 0 ){
Flag = true;
}
}
Catch (Exception ex)
{
Console. WriteLine (ex. Message );
}
Return true;
}
Public bool Add (string name, string pwd)
{
Bool flag = false;
Try
{
String str = "data source =.; initial Catalog = MySchool; uid = sa; pwd = mnbv ";
SqlConnection conn = new SqlConnection (str );
Conn. Open ();
String SQL = "insert into Student values ('" + name + "', '" + pwd + "')";
SqlCommand cmd = new SqlCommand (SQL, conn );
Int num = Convert. ToInt32 (cmd. ExecuteScalar ());
If (num> 0)
{
}
}
Catch (Exception ex)
{
Console. WriteLine (ex. Message );
}
Return true;
}
Public static List <Student> Const ()
{
List <Student> list = new List <Student> ();
DataSet da = new DataSet ();
String SQL = "select * from Student ";
SqlConnection conn = new SqlConnection (SqlHelper. ConStr );
Try
{
Conn. Open ();
SqlCommand cmd = new SqlCommand (SQL, conn );
SqlDataReader dr = cmd. ExecuteReader ();
While (dr. Read ())
{
Student st = new Student ();
St. name = dr ["name"]. ToString ();
St. pwd = dr ["pwd"]. ToString ();
List. Add (st );
}
Dr. Close ();
Return list;
}
Catch (Exception ex)
{
Throw ex;
}
Finally
{
Conn. Close ();
}
}
Public string name {get; set ;}
Public string pwd {get; set ;}
}
}