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:             { 

解决方案 »

  1.   

    score字段是什么类型的 有可能不是数字 或者该列值为空
      

  2.   

    那就应该是select max(Score) as score from SC where teaID=@teaId and CourseID=@courseId";这个查询语句没有查找到相应的值了!
      

  3.   


    为空 转换的时候当然出错了int max = (Convert.ToString(sdr["score"]).Trim().Length==0)? 0 : Convert.ToInt32(sdr["score"].ToString ());
      

  4.   

    select isnull(max(Score),0) as score from SC where teaID=@teaId and CourseID=@courseId
    看下吧
      

  5.   

    用Convert.ToInt32(这里就不要.ToString()了)
      

  6.   

    既然scoure列为空,应该是语句出错啦或者逻辑错啦吧,现在数据库里运行下语句吧,正确后再写入asp.net里面!