Layered, new third board layered

Source: Internet
Author: User

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 ;}
}
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.