Reputation: 849
I am working with SqlServerCe
. The insert
query is working properly but the update
query gives an exception.
Here is my code:
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();
It gives an error at the line cmd.ExecuteNonQuery();
An exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in
System.Data.SqlServerCe.dll but was not handled in user code
Upvotes: 0
Views: 51
Reputation: 48537
You are missing an AND
before sectionname
. Corrected SQL below:
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 + "'";
Upvotes: 3
Reputation: 297
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 + "'";
Upvotes: 0