public bool Insert(postBLL asp) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "INSERT INTO tbl_post (PostName, DateTime) VALUES (@PostName, @DateTime)"; SqlCommand cmd = new SqlCommand(sql, conn); //cmd.Parameters.AddWithValue("@AspirantID", asp.AspirantID); cmd.Parameters.AddWithValue("@PostName", asp.PostName); cmd.Parameters.AddWithValue("@DateTime", asp.DateTime); conn.Open(); int row = cmd.ExecuteNonQuery(); //ExecuteNonQuery command will execute the Query and return number of Rows affected from database //If the quary excuted successfully then the Value of row will be greater than 0 else it will less than 0 if (row > 0) { //Quary successfull isSuccess = true; } else { //Quary failed isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }
public bool Delete(postBLL asp) { bool isSuccess = false; SqlConnection conn = new SqlConnection(myconnstrng); try { string sql = "DELETE FROM tbl_post WHERE PostID=@PostID"; SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@PostID", asp.PostID); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { //Quary execute successfull isSuccess = true; } else { //Quary execution fail isSuccess = false; } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(isSuccess); }