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;
}
}