Beispiel #1
0
        // Updating the database
        public bool Update(SSD ClassSSD)
        {
            var isSuccess  = false;
            var connection = new SqlConnection(connectionString);

            try
            {
                // Query to update the data
                var query = "UPDATE SSD SET Manufacturer=@Manufacturer, Name=@Name, " +
                            "CapacityGB=@CapacityGB, CacheMb=@CacheMb, Interface=@Interface, " +
                            "Price=@Price WHERE SSDId=@SSDId";

                var cmd = new SqlCommand(query, connection);

                cmd.Parameters.AddWithValue("@SSDId", ClassSSD.Id);
                cmd.Parameters.AddWithValue("@Manufacturer", ClassSSD.Manufacturer);
                cmd.Parameters.AddWithValue("@Name", ClassSSD.Name);
                cmd.Parameters.AddWithValue("@CapacityGB", ClassSSD.CapacityGB);
                cmd.Parameters.AddWithValue("@CacheMb", ClassSSD.CacheMb);
                cmd.Parameters.AddWithValue("@Interface", ClassSSD.Interface);
                cmd.Parameters.AddWithValue("@Price", ClassSSD.Price);

                connection.Open();
                int rows = cmd.ExecuteNonQuery();
                isSuccess = rows > 0 ? true : false;
            }
            finally
            {
                connection.Close();
            }

            return(isSuccess);
        }
Beispiel #2
0
        public bool Delete(SSD ClassSSD)
        {
            var isSuccess  = false;
            var connection = new SqlConnection(connectionString);

            try
            {
                // Query to delete the data
                var query = "DELETE FROM SSD WHERE SSDId=@SSDId";

                var cmd = new SqlCommand(query, connection);

                cmd.Parameters.AddWithValue("@SSDId", ClassSSD.Id);

                connection.Open();
                int rows = cmd.ExecuteNonQuery();
                isSuccess = rows > 0 ? true : false;
            }
            finally
            {
                connection.Close();
            }

            return(isSuccess);
        }
Beispiel #3
0
        // Adding to database
        public bool Insert(SSD ClassSSD)
        {
            var isSuccess  = false;
            var connection = new SqlConnection(connectionString);

            try
            {
                // SQL Query to Insert the data
                var query = "INSERT INTO SSD (SSDId, Manufacturer, Name, CapacityGB, CacheMb, Interface, Price) " +
                            "VALUES(@SSDId, @Manufacturer, @Name, @CapacityGB, @CacheMb, @Interface, @Price)";

                var cmd = new SqlCommand(query, connection);

                cmd.Parameters.AddWithValue("@SSDId", ClassSSD.Id);
                cmd.Parameters.AddWithValue("@Manufacturer", ClassSSD.Manufacturer);
                cmd.Parameters.AddWithValue("@Name", ClassSSD.Name);
                cmd.Parameters.AddWithValue("@CapacityGB", ClassSSD.CapacityGB);
                cmd.Parameters.AddWithValue("@CacheMb", ClassSSD.CacheMb);
                cmd.Parameters.AddWithValue("@Interface", ClassSSD.Interface);
                cmd.Parameters.AddWithValue("@Price", ClassSSD.Price);

                connection.Open();
                int rows = cmd.ExecuteNonQuery();
                isSuccess = rows > 0 ? true : false;
            }
            finally
            {
                connection.Close();
            }

            return(isSuccess);
        }