数据库删除问题
大家好又是我,这两天数据库总是和我较劲*********************************我用了三层架构的发法对数据库进行操作,第一步是先读取数据库大家请看代码public class StaffDAL
{
/// <summary>
/// 获取所有数据 数据访问层 我想写个删除数据库数据操作,页面上以及数据库中的数据都删了
/// </summary> 哪位大神出来帮帮忙啊
/// <returns></returns>
///
public IList<Staff> GetAllList()
{
IList<Staff> listStaff = new List<Staff>();
string sql = "select * from Staff ";
SqlConnection con = new SqlConnection("server=.;database=test;uid=sa;pwd=server;");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
sda.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
Staff s = new Staff();
s.Id = Convert.ToInt32(dt.Rows[i][0]);
s.Name = Convert.ToString(dt.Rows[i][1]);
s.Address = Convert.ToString(dt.Rows[i][2]);
s.Phone = Convert.ToString(dt.Rows[i][3]);
s.Email = Convert.ToString(dt.Rows[i][4]);
s.GroupID = Convert.ToString(dt.Rows[i][5]);
listStaff.Add(s);
}
return listStaff;
}
}
//////////////////////////////////////////////////////业务逻辑层///////////////////////////////////////////////
public class StaffBLL
{
public IList<Staff> GetAllList()
{
StaffDAL _StaffDAL = new StaffDAL();
return _StaffDAL.GetAllList();
}
public IList<Staff> GetList()
{
StaffDAL _StaffDAL = new StaffDAL();
IList<Staff> list = _StaffDAL.GetAllList();
IList<Staff> list2 = new List<Staff>();
foreach (var item in list)
{
if (item.Address.Length == 2)
{
list2.Add(item);
}
}
return list2;
}
}
/////////////////////////////////////////// 页面调用////////////////////////////////////
public partial class test : System.Web.UI.Page
{
StaffBLL _StaffBLL = new StaffBLL();
protected IList<Staff> list = new List<Staff>();
protected void Page_Load(object sender, EventArgs e)
{
list = _StaffBLL.GetAllList();
}
protected void LinkButton1_Click1(object sender, EventArgs e)
{
StaffDAL _StaffDAL = new StaffDAL();
_StaffDAL.Delete();
}
}