Reputation: 849
When try to execute get error
cmd.CommandText = "insert into Finalresult (section_name,examid,userid,solveqty,dateexam,totalqty) values('" + section + "','" + examis + "','" + UserId + "','" + newId + "','" + DateTime.Now + "'"+
",'(Select count(SubQno) from Question where Section_name='" + section + "')')";
cmd.ExecuteNonQuery();
get error at line cmd.ExecuteNonQuery(); error message is There was an error parsing the query. [ Token line number = 1,Token line offset = 229,Token in error = Interactive ]
Upvotes: 0
Views: 313
Reputation: 5578
You don't need the single quotes around your nested select.
cmd.CommandText = "insert into Finalresult (section_name,examid,userid,solveqty,dateexam,totalqty) values('" + section + "','" + examis + "','" + UserId + "','" + newId + "','" + DateTime.Now + "',(Select count(SubQno) from Question where Section_name='" + section + "'))";
cmd.ExecuteNonQuery();
You should not be doing it this way anyway, you should use command parameters to build up your query.
e.g.
cmd.CommandText = "insert into Finalresult (section_name,examid,userid,solveqty,dateexam,totalqty) values(@section, @exam, @user, @solve, @date, (Select count(SubQno) from Question where Section_name=@section))";
cmd.Parameters.AddWithValue("@section", section);
Upvotes: 1