急需帮忙!!成绩显示问题
string teaId = Session["userName"].ToString();string courseId = ddlCName.SelectedValue;
string querySql = "select max(Score) as score from SC where teaID=@teaId and CourseID=@courseId";
SqlParameter[] param = {
new SqlParameter("@teaId", SqlDbType.VarChar),
new SqlParameter ("@courseId",SqlDbType .VarChar )
};
param[0].Value = teaId;
param[1].Value = courseId;
SqlDataReader sdr = dbhelp.ExecuteReader(CommandType.Text, querySql, param);
if (sdr.Read())
{
//判断成绩是否提交
int max = Convert.ToInt32(sdr["score"].ToString ());
if (max >= 0)//若成绩已经提交则隐藏GridView
{
GridView1.Visible = false;
Button1.Visible = false;
Response.Write("<script language=javascript>alert('该课程成绩已经提交!')</script>");
}
else
{//若没有提交成绩,则取出选课的学生,绑定GridView,填写成绩
GridView1.Visible = true;
Button1.Visible = true;
string sql = "select Student.stuID, Student.stuName,Class.ClassName from Student,Class,SC where SC.teaID=@teaId "
+ "and SC.CourseID=@courseId and Student.stuID=SC.stuID and Class.ClassID=Student.ClassID order by SC.stuID ASC";
SqlParameter[] param = {
new SqlParameter("@teaId", SqlDbType.VarChar),
new SqlParameter ("@courseId",SqlDbType .VarChar )
};
param[0].Value = teaId;
param[1].Value = courseId;
DataSet ds = dbhelp.ExecuteDataSet(CommandType.Text, sql, param);
GridView1.DataSource = ds;
GridView1.DataBind();
}
但是运行总是出现“输入字符串的格式不正确。”
//判断成绩是否提交
行 61: int max = Convert.ToInt32(sdr["score"].ToString ());
行 62: if (max >= 0)
行 63: {
--------------------编程问答-------------------- F5找出异常。 --------------------编程问答-------------------- score字段是什么类型的 有可能不是数字 或者该列值为空 --------------------编程问答-------------------- score的数据类型是? --------------------编程问答-------------------- int型,而且Score列的值为空 --------------------编程问答-------------------- 那就应该是select max(Score) as score from SC where teaID=@teaId and CourseID=@courseId";
这个查询语句没有查找到相应的值了! --------------------编程问答-------------------- 怎样判断成绩已经提交过呢 --------------------编程问答--------------------
为空 转换的时候当然出错了
int max = (Convert.ToString(sdr["score"]).Trim().Length==0)? 0 : Convert.ToInt32(sdr["score"].ToString ());
--------------------编程问答-------------------- isnull(max(Score),0) --------------------编程问答--------------------
怎么不回话了?~· --------------------编程问答-------------------- 断点在地方出现异常 --------------------编程问答-------------------- 看sdr["score"]的值 --------------------编程问答-------------------- select isnull(max(Score),0) as score from SC where teaID=@teaId and CourseID=@courseId
看下吧 --------------------编程问答-------------------- 用Convert.ToInt32(这里就不要.ToString()了) --------------------编程问答-------------------- 成绩提交了的依据是什么? --------------------编程问答-------------------- 为什么要"max(Score)"啊? --------------------编程问答-------------------- 既然scoure列为空,应该是语句出错啦或者逻辑错啦吧,现在数据库里运行下语句吧,正确后再写入asp.net里面! --------------------编程问答-------------------- 跟踪断点,来调试运行!找出问题的所在,细心点
补充:.NET技术 , ASP.NET