.写student类中的select,delete,update,insert方法并在objectDataSource中应用

public class Student
    {
        public int SID { get; set; }
        public string SNAME { get; set; }
        public string SEX { get; set; }
        public int AGE { get; set; }
        public DataTable StudentSelect()
        {
            string sql = "select sId,sName,sSex,sAge from Student";
            return SqlHelper.ExecuteDataTable(sql);
        }
        public int StudentDelete(int sId)
        {
            string sql = "delete from Student where sId=@sId";
            SqlParameter pms = new SqlParameter("@sId",sId);
            return SqlHelper.ExecuteNonQuery(sql,pms);

        }
        public int StudentUpdate(int sId, string sName, string sSex, int sAge)
        {
            string sql = "update Student set sName=@sname,sSex=@sex,sAge=@age where sId=@sid";
            SqlParameter[] pmss = new SqlParameter[]
            {
            new SqlParameter("@sname",sName),
            new SqlParameter("@age",sAge),
            new SqlParameter("@sex",sSex),
            new SqlParameter("@sid",sId)
            };
            return SqlHelper.ExecuteNonQuery(sql, pmss);
        }
        public DataTable StudentInsert(string sName, string sSex, int sAge)
        {
            string sql = "insert into Student(sName,sSex,sAge)values(@sname,@sex,@age)";
            SqlParameter[] pms = new SqlParameter[]
            {
            new SqlParameter("@sname",sName),
            new SqlParameter("@age",sAge),
            new SqlParameter("@sex",sSex)
          
            };
            return  SqlHelper.ExecuteNonQuery(sql,pms);
           
        }
        public List<Student> GetStudents()
        {
            string sql = "select sId,sName,sSex,sAge from Student";
            DataTable dt = SqlHelper.ExecuteDataTable(sql);
            List<Student> list=new List<Student>();
            foreach(DataRow row in dt.Rows)
            {
                Student stu = new Student();
                stu.SID = (int)row[0];
                stu.SNAME = row[1].ToString();
                stu.SEX = row[2].ToString();
                stu.AGE = Convert.ToInt32(row[3]);
                list.Add(stu);
            }
            return list;
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值