public bool Delete(notavailable ci) { bool isSuccess = false; SqlConnection Con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\TimeTableDatabase.mdf;Integrated Security=True"); try { string sql = "DELETE FROM Not_Avai_time WHERE id=@id"; SqlCommand cmd = new SqlCommand(sql, Con); cmd.Parameters.AddWithValue("@id", ci.id); Con.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { } finally { Con.Close(); } return(isSuccess); }
public bool Insert(notavailable ci) { bool isSuccess = false; SqlConnection Con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\TimeTableDatabase.mdf;Integrated Security=True"); try { string sql = "INSERT INTO Not_Avai_time(lec,grp,sid,dur,stime,etime)VALUES(@lec,@grp,@sid,@dur,@stime,@etime)"; SqlCommand cmd = new SqlCommand(sql, Con); cmd.Parameters.AddWithValue("@lec ", ci.lec); cmd.Parameters.AddWithValue("@grp", ci.grp); cmd.Parameters.AddWithValue("@sid", ci.sid); cmd.Parameters.AddWithValue("@dur", ci.dur); cmd.Parameters.AddWithValue("@stime", ci.stime); cmd.Parameters.AddWithValue("@etime", ci.etime); Con.Open(); int rows = cmd.ExecuteNonQuery(); if (rows > 0) { isSuccess = true; } else { isSuccess = false; } } catch (Exception ex) { } finally { Con.Close(); } return(isSuccess); }