public void InsertRoom(Room room) { SqlConnection connection = null; try { connection = retrieveConnection(); SqlCommand command = new SqlCommand("insert into room values (@Room, @Zipcode)", connection); command.Parameters.Add(new SqlParameter("Room", room.RoomKey)); command.Parameters.Add(new SqlParameter("Zipcode", room.Zipcode)); command.ExecuteNonQuery(); } finally { connection.Close(); } }
public Room QueryRoom(string roomKey) { SqlConnection connection = null; SqlDataReader reader = null; Room room = null; try { connection = retrieveConnection(); SqlCommand command = new SqlCommand("select Room, Zipcode from room where Room = @roomKey", connection); command.Parameters.Add(new SqlParameter("roomKey", roomKey)); reader = command.ExecuteReader(); if (reader.Read()) { room = new Room(); room.RoomKey = reader["Room"].ToString(); room.Zipcode = reader["Zipcode"].ToString(); } else throw new Exception("Room not found!"); return room; } finally { reader.Close(); connection.Close(); } }
public void UpdateRoom(Room room, string roomKey) { SqlConnection connection = null; try { connection = retrieveConnection(); SqlCommand command = new SqlCommand("update room set Room = @Room, Zipcode = @Zipcode where Room = @roomKey", connection); command.Parameters.Add(new SqlParameter("Room", room.RoomKey)); command.Parameters.Add(new SqlParameter("Zipcode", room.Zipcode)); command.Parameters.Add(new SqlParameter("roomKey", roomKey)); command.ExecuteNonQuery(); } finally { connection.Close(); } }