public static int AddStudent(Student stu)
{
int num = 0;
//关键是存储过程
string sql = "addNewStudent";
SqlParameter p=new SqlParameter();
p.ParameterName="@newId";
p.SqlDbType=SqlDbType.Int;
p.Direction=ParameterDirection.Output;
bool sex=stu.StuSex=="男"?true:false;
SqlParameter[] param={new SqlParameter("@name",stu.StuName),
new SqlParameter("@sex",sex),
new SqlParameter("@birthday",stu.StuBirthday),
new SqlParameter("@hight",stu.StuHeight),
new SqlParameter("@weight",stu.StuWeight),
new SqlParameter("@cid",stu.ClassId),
new SqlParameter("@money",stu.Money),
new SqlParameter("@password",stu.StuPwd),
new SqlParameter("@memo",stu.Remark),
new SqlParameter("@rid",stu.RoleId),p};
num = SQLHelper.ExecuteNonQuery(SQLHelper.ConnectionStr, CommandType.StoredProcedure, sql, param);
if (num > 0)
{
return int.Parse(p.Value.ToString());
}
else
{
return -1;
}
}