返回datatable
public DataTable StudentsSelect()
{
string sql = "select sid,sname,sex,age,photo from student";
return sqlHealpler.sqlHealper.ExecuteTable(sql);
}
public int StudentDelete(int sid)
{
string sql = "delete from student where sid=@id";
SqlParameter pms=new SqlParameter("@id",sid);
return sqlHealpler.sqlHealper.ExecturNonQuery(sql,pms);
}
public int StudentInsert(int sid, string sname, string sex, int age, string photo)
{
string sql = "insert into student values(@sname,@sex,@age,@photo)";
SqlParameter[] pms = new SqlParameter[]
{
new SqlParameter("@sname",sname),
new SqlParameter("@sex",sex),
new SqlParameter("@age",age),
new SqlParameter("@photo",photo),
//new SqlParameter("@id",sid)
};
return sqlHealpler.sqlHealper.ExecturNonQuery(sql, pms);
}
public int StudentUpdate(int sid,string sname,string sex,int age,string photo)
{
string sql = "Update student set sname=@sname,sex=@sex,age=@age,photo=@photo where sid=@id";
SqlParameter[] pms = new SqlParameter[]
{
new SqlParameter("@sname",sname),
new SqlParameter("@sex",sex),
new SqlParameter("@age",age),
new SqlParameter("@photo",photo),
new SqlParameter("@id",sid)
};
return sqlHealpler.sqlHealper.ExecturNonQuery(sql, pms);
}
********************************返回list
public int sid { get; set; }
public string sname { get; set; }
public string sex { get; set; }
public int age { get; set; }
public string photo { get; set; }
public List<Student> GetStudents()
{
string sql = "select sid,sname,sex,age,photo from student";
DataTable dt = sqlHealpler.sqlHealper.ExecuteTable(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]);
stu.photo = row[4].ToString();
list.Add(stu);
}
return list;
}