日期:2014-05-17  浏览次数:20514 次

提示Week附近有错误…………
sql语句放在数据库中查询没有错误,可是放在后台代码中就提醒“'Week1' 附近有语法错误。关键字 'where' 附近有语法错误。 ”下面是我的代码,请大神们指点迷津~~~


//从数据库的Score表中求出平均值后存储到Teacher表相对应的WeekN字段中
  //a就相当于Teacher表中的Week1,Week2……,
  public int insertTeacher()
  {
   
  string a = "Week"+this.DropDownList2.SelectedIndex.ToString();
  //string Week="select week from score where TeacherName='"+DropDownList2.Text+"'";
  string sql = "update Teacher set '" + a + "'= (select (avg(TiNO1)+avg(TiNO2)+avg(TiNO3)+avg(TiNO4)+avg(TiNO5)+avg(TiNO6)+avg(TiNO7)+avg(TiNO8)+avg(TiNO9)+avg(TiNO10))/10 " +
  "from Score where TeacherName='" + DropDownList1.Text + "' group by TeacherName) where TeacherName='" + DropDownList1.Text + "'";

  int j = DBConnection.updateTable(sql);
  return j;
   
   
   
  }


------解决方案--------------------
问题已解决,是在a附近多了个单引号,是我2了