标题:数据库删除问题
只看楼主
努力吼
Rank: 2
等 级:论坛游民
帖 子:64
专家分:51
注 册:2012-11-12
结帖率:100%
 问题点数:0 回复次数:1 
数据库删除问题
大家好又是我,这两天数据库总是和我较劲*********************************我用了三层架构的发法对数据库进行操作,第一步是先读取数据库大家请看代码
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();
        }
    }
搜索更多相关主题的帖子: 数据库数据 returns public 
2013-03-06 09:00
努力吼
Rank: 2
等 级:论坛游民
帖 子:64
专家分:51
注 册:2012-11-12
得分:0 
我给大家截个图

新手上路,多多帮助。。。嘿嘿
2013-03-06 09:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-399856-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.311296 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved