dal层连接数据库

  • Post author:
  • Post category:其他


三层架构的运用,学习的是类库里的DAL层,BLL层,Model层,和web应用程序UL层。首先是DAL层里连接数据库里数据的DBhelper。

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Data.SqlClient;–连接数据库

using System.Data;–连接数据库

public static string connstr = “server=.;uid=登录名;pwd=密码;database=数据库名;”;

//查询语句

public static DataTable ExcuteTable(string sql)

{


SqlDataAdapter sda = new SqlDataAdapter(sql, connstr);

DataTable dt = new DataTable();

sda.Fill(dt);

return dt;

}

//增删改语句

public static int ExcuteNonQuery(string sql)

{


SqlConnection conn = new SqlConnection(connstr);

conn.Open();

SqlCommand comm = new SqlCommand(sql, conn);

return comm.ExecuteNonQuery();

}



版权声明:本文为ay991120原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。