2014-03-19 3 views
0

나는 SqlServerCe과 일하고 있습니다. insert 쿼리가 제대로 작동하지만 update 쿼리가 예외를 제공합니다. 그것은 당신이 ANDsectionname 전에 누락 라인 cmd.ExecuteNonQuery();왜 업데이트 쿼리가 작동하지 않습니까?

An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in 
System.Data.SqlServerCe.dll but was not handled in user code 
+0

모든 혼합 변수 – Prix

+0

이 예외 사항을 게시하지 않도록하려면 prepared statement를 사용해야합니다. –

답변

0
cmd.CommandText = " Update [Solve_Student_question] set Answ= '" + ans + "' ,Start_time='" + sTime + "',End_time='" + eTime + "' where Qno='" + Qno + "' AND User_id='" + userid + "' and Exame_id='" + examid + "'and sectionname='" + sectionname + "'"; 
3

에서 오류를 제공

SqlCeConnection _connection _connection = new SqlCeConnection(@"Data Source=MyDatabase#1.sdf;Password=xxxxx;"); 
_connection.Open(); 

cmd.Connection = _connection; 
cmd.CommandText = " UPDATE [Solve_Student_question] 
         SET Answ= '" + ans + "' , 
          Start_time='" + sTime + "', 
          End_time='" + eTime + "' 
        WHERE Qno='" + Qno + "' AND 
          User_id='" + userid + "' AND 
          Exame_id='" + examid + "' sectionname='" + sectionname + "'"; 
cmd.CommandType = CommandType.Text; 
cmd.ExecuteNonQuery(); 

_connection.Close(); 

:

여기 내 코드입니다. 아래의 수정 된 SQL :

cmd.CommandText = " UPDATE [Solve_Student_question] 
        SET Answ= '" + ans + "' , 
         Start_time='" + sTime + "', 
         End_time='" + eTime + "' 
       WHERE Qno='" + Qno + "' AND 
         User_id='" + userid + "' AND 
         Exame_id='" + examid + "' AND sectionname='" + sectionname + "'"; 
관련 문제