c# - Insert function to insert record in SQL table working properly but Update Function to Update Record is not working properly -
these functions update student record , insert student record in sql batabase.
public void updatestudent(ref student stu, string rollno) //update values corresponding roll number 'rollno' { try { connection.open(); //i have defined connection , command command = new sqlcommand("update student set firstname='"+stu.firstname+"',lastname='"+stu.lastname+"',yearofadmission="+stu.yearofadmission+",branch='"+stu.branch+"' rollno='"+rollno+"'", connection); //yearofadmission int command.executenonquery(); } catch (exception) { throw; } { if (connection != null) connection.close(); } } public void insertstudent(ref student s) { try { connection.open(); command = new sqlcommand("insert student values('"+s.rollno+"','"+ s.firstname+"','"+s.lastname+"',"+s.yearofadmission+",'"+s.branch+"','"+s.password+"')", connection); command.executenonquery(); } catch (exception) { throw; } { if (connection != null) connection.close(); } }
my second function 'insertstudent' insert value sql table working correctly , inserting values database table. first function 'update student' not updating values in databse table. not providing error either. wrong?
in advance!
check make sure rollno passed update function correct. if command not throwing error, it's executing correctly , ending updating nothing because no record hits supplied rollno.
put break point @ beginning of update function , check supplied value of rollno.
also, roll no. in insert statement subset of 's' whereas in update, provided separately, may need check if that's ok.
Comments
Post a Comment