以前学的dbhelp
string str = "Data Source=.;Initial Catalog=BookManagement;Integrated Security=True";
//定义查询的方法
public DataTable Query(string sql)
{
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataTable dt = new DataTable();
da.Fill(dt);
conn.Close();
return dt;
}
//定义添加的方法
public int excuate(string sql)
{
SqlConnection conn = new SqlConnection(str);
conn.Open();
SqlCommand comm = new SqlCommand(sql, conn);
int num = comm.ExecuteNonQuery();
return num;
}
}
三层架构基本框架