public bool UpdateHostel(Hostel hostel) { dbConnection = new DatabaseConnection(); dbConnection.CreateQuery("UPDATE Hostels SET HostelName='" + hostel.HostelName + "', HostelAddress='" + hostel.HostelAddress + "', HostelType='" + hostel.HostelType + "', HostelCapacity='" + hostel.HostelCapacity + "' WHERE HostelId=" + hostel.HostelId); if ((dbConnection.DoNoQuery()) < 1) { dbConnection.Dispose(); dbConnection = null; return(false); } dbConnection.Dispose(); dbConnection = null; return(true); }
public bool CreateHostel(Hostel hostel) { dbConnection = new DatabaseConnection(); dbConnection.CreateQuery("INSERT INTO Hostels(HostelName, HostelAddress, HostelType, HostelCapacity, AdminId) VALUES ('" + hostel.HostelName + "','" + hostel.HostelAddress + "','" + hostel.HostelType + "','" + hostel.HostelCapacity + "'," + hostel.AdminId + ")"); if ((dbConnection.DoNoQuery()) < 1) { dbConnection.Dispose(); dbConnection = null; return(false); } dbConnection.Dispose(); dbConnection = null; return(true); }
public Hostel GetHostel(string hostelId) { dbConnection = new DatabaseConnection(); dbConnection.CreateQuery("SELECT * FROM Hostels WHERE HostelId=" + hostelId); SqlDataReader reader = dbConnection.DoQuery(); Hostel hostel = new Hostel(); while (reader.Read()) { hostel.HostelId = reader["HostelId"].ToString(); hostel.HostelName = reader["HostelName"].ToString(); hostel.HostelAddress = reader["HostelAddress"].ToString(); hostel.HostelType = reader["HostelType"].ToString(); hostel.HostelCapacity = reader["HostelCapacity"].ToString(); hostel.AdminId = reader["AdminId"].ToString(); } dbConnection.Dispose(); dbConnection = null; return(hostel); }