department表中的departmentid根据newdepartment进行更新~
String StrUpDate = "update departmentid from department where departmentid='" + NewDepartment+"'";
上面是小菜我写的,求高手帮我~~~

解决方案 »

  1.   

    "update departmentid from department where departmentid='" + NewDepartment;
      

  2.   

    "update departmentid from department where departmentid=" + NewDepartment;
      

  3.   

    UPDATE department 
    SET departmentid =NewDepartment
    where ...
      

  4.   

    忘了说了,NewDepartment是一个定义好的变量,根据teacherId应该怎么写呢?~
      

  5.   

    string updateSQL="UPDATE department SET departmentid='"+NewDepartment+"' WHERE departmentid='"+teacherId+"'"
      

  6.   

    TextBox myTeacherId = DetailsViewMove.FindControl("TextBoxTeacherId") as TextBox;
            if (myTeacherId != null)
            {
                String StrTeacherId = "UPDATE department SET departmentid =" + NewDepartment + "where TeacherId='" + myTeacherId.Text + "'";
                SqlCommand myCommand2 = new SqlCommand(StrTeacherId, myConnection);
                SqlDataReader myReader2 = myCommand2.ExecuteReader();
                
            }现在只是能读出来!
      

  7.   

    string updateSQL="UPDATE department SET departmentid='"+NewDepartment+"' WHERE departmentid='"+teacherId+"'"
    SqlCommand sqlcmd = new SqlCommand(StrTeacherId, myConnection);
    sqlcmd.ExecuteNonQuery();
      

  8.   

    SqlCommand myCommand2=myConnection.CreateCommand();
    myCommand2.CommandText=StrTeacherId;
    myCommand2.ExecuteNonQuery();
      

  9.   

    TextBox myTeacherId = DetailsViewMove.FindControl("TextBoxTeacherId") as TextBox;
            if (myTeacherId != null)
            {
                String StrTeacherId = "UPDATE department SET departmentid =" + NewDepartment + " where TeacherId='" + myTeacherId.Text + "'";
                SqlCommand myCommand2 = myConnection.CreateCommand();
                myCommand2.CommandText = StrTeacherId;
                myCommand2.ExecuteNonQuery();
                //SqlCommand sqlcmd = new SqlCommand(StrTeacherId, myConnection);
                //sqlcmd.ExecuteNonQuery();        }
    为什么出错啊?提示TeacherId无效,查看详细是应为where后面的TeacherId 是空.为什么?有高手知道么?
      

  10.   

    估计是,你打字的过程中,有多余的空格。sql对于空格很敏感。
    建议对代码中间的空格都检查一遍,注意一下全半角,还有单引号。
      

  11.   

    看过myTeacherId.Text里有没有东西吗?