public bool Update(NbDays n) { bool isSucces = false; //Connect database SqlConnection conn = new SqlConnection(myconnstrng); try { //create update sql query string sql = "UPDATE NbDays SET days=@days WHERE week=@week"; //command SqlCommand cmd = new SqlCommand(sql, conn); //create parameter cmd.Parameters.AddWithValue("@days", n.days); cmd.Parameters.AddWithValue("@week", n.week); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSucces = true; } else { isSucces = false; } } catch (Exception ex) { } finally { conn.Close(); } return(isSucces); }
public bool Insert(NbDays n) { bool isSuccess = false; //Connect database SqlConnection conn = new SqlConnection(myconnstrng); try { //create insert sql query string sql = "INSERT INTO NbDays(days) VALUES(@days)"; //Create command using sql,conn SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@days", n.days); conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { } finally { conn.Close(); } return(isSuccess); }
public bool Delete(NbDays n) { bool isSuccess = false; //create SQL Connection SqlConnection conn = new SqlConnection(myconnstrng); try { //Sql delete data string sql = "DELETE FROM NbDays WHERE week=@week "; //creating sql command SqlCommand cmd = new SqlCommand(sql, conn); cmd.Parameters.AddWithValue("@week", n.week); //Open Connection conn.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { } finally { conn.Close(); } return(isSuccess); }