//-------------------------------------------------------------------- // Build the Insert command String //-------------------------------------------------------------------- private String BuildInsertCommand(EventsFeedback mngcom) { String command; command = "update feedbackstudenttoevents_P3 set managercomment ='" + mngcom.Managercomment + "' where feedbackstudenttoevents_P3.fbEventNum=" + mngcom.FbEventNum; return(command); }
public HttpResponseMessage Insertcomment([FromBody] EventsFeedback addmngcom) { try { addmngcom.Insertcomment(); return(Request.CreateResponse(HttpStatusCode.OK, "Comment added successfully")); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message)); } }
public List <EventsFeedback> GetFBev(int eventCode) { SqlConnection con = null; List <EventsFeedback> FBList = new List <EventsFeedback>(); try { con = connect1("DBConnectionString"); String selectSTR = "select * from feedbackstudenttoevents_P3 inner join student_P on student_P.mail=feedbackstudenttoevents_P3.studentmail where feedbackstudenttoevents_P3.eventCode=" + eventCode; SqlCommand cmd = new SqlCommand(selectSTR, con); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dr.Read()) { // Read till the end of the data into a row EventsFeedback FB = new EventsFeedback(); FB.FbEventNum = Convert.ToInt16(dr["fbEventNum"]); FB.Student = (new Student { Fname = (string)dr["firstName"] }); FB.Student.Mail = (string)dr["mail"]; FB.CommentText = (string)dr["commenttext"]; FB.CommentDate = Convert.ToDateTime(dr["commentdate"]); FB.Managercomment = Convert.ToString(dr["managercomment"]); FBList.Add(FB); } return(FBList); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { con.Close(); } } }
public int Insertcomment(EventsFeedback mngcom) { SqlConnection con; SqlCommand cmd; try { con = connect1("DBConnectionString"); // create the connection } catch (Exception ex) { // write to log throw (ex); } String cStr = BuildInsertCommand(mngcom); // helper method to build the insert string cmd = CreateCommand1(cStr, con); // create the command try { int numEffected = cmd.ExecuteNonQuery(); // execute the command return(numEffected); } catch (Exception ex) { // write to log throw (ex); } finally { if (con != null) { // close the db connection con.Close(); } } }