using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//1.引入命名空间
using System.Data.SqlClient;
using System.Data;
namespace DormitoryManager
{
class DBHelper
{
private static SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Dormitory;Integrated Security=True");
//获取一个DataTable的方法
public static DataTable GetDataTable(string sql)
{
DataTable dt = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
sda.Fill(dt);
return dt;
}
//执行增删改的方法
public static bool ExcutNonQuery(string sql)
{
conn.Open();
SqlCommand comm = new SqlCommand(sql, conn);
int n= comm.ExecuteNonQuery();
conn.Close();
return n > 0;
}
}
}