数据库
create database Test
go
use Test;
go
create table UserInfo
(
id int primary key identity(1,1),
name varchar(20) not null unique,
pwd varchar(12) not null,
role int default(0) check(role=0 or role=1)
)
BLL
using DAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BLL
{
public class UserInfoBLL
{
public static UserInfo Select(string name, string pwd)
{
return UserInfoDAL.Select(name, pwd);
}
}
}
DAL
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using SqlData = System.Data.SqlClient.SqlDataAdapter;
namespace DAL
{
public class SqlHelper
{
//连接字段
private static string strConn = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
//查询
public static DataTable Query(string sql)
{
SqlData adapter = new SqlData(sql, strConn);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
//非查询 using close
public static int NonQuery(string sql)
{
using (SqlConnection sqlConnection = new SqlConnection(strConn))
{
using (SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection))
{
sqlConnection.Open();
return sqlCommand.ExecuteNonQuery();
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using SqlData = System.Data.SqlClient.SqlDataAdapter;
namespace DAL
{
public class SqlHelper
{
//连接字段
private static string strConn = ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
//查询
public static DataTable Query(string sql)
{
SqlData adapter = new SqlData(sql, strConn);
DataTable table = new DataTable();
adapter.Fill(table);
return table;
}
//非查询 using close
public static int NonQuery(string sql)
{
using (SqlConnection sqlConnection = new SqlConnection(strConn))
{
using (SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection))
{
sqlConnection.Open();
return sqlCommand.ExecuteNonQuery();
}
}
}
}
}
Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Model
{
public class UserInfo
{
public int Id { get; set; }
public string Name { get; set; }
public string Pwd { get; set; }
public int Role { get; set; }
}
}