我正在使用SqlServerCe
。 insert
查询工作正常,但update
查询提供了例外。
这是我的代码:
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();
它在行cmd.ExecuteNonQuery();
An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in
System.Data.SqlServerCe.dll but was not handled in user code
答案 0 :(得分:3)
AND
之前您遗漏了sectionname
。修正了以下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 + "'";
答案 1 :(得分: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 + "'";