The "Best Answer"

How Can Testing Be Bad?

An imaginary programming test question
This is how I would answer the question if the question was part of a real job.

There are clearly some styling practices that are not flavour of the month.
  • Variable names prefixed with their type because it is helpful for others.

  • Variables declared at the top of the function as declarations near their first use hide code functionality.
There is an unnecessary string assignment for the SQL statement.

All resources are released and there is a try/catch block.

Because It is My Way!

This is my prefered method because it has the data access in a separate layer without any unnecessary intermediate code or files and no run time interpretation that is also version dependent.
With a whole lot of caveats I would regard this as the best answer as it is the closest of the three answers to being ready to put into a live system.

It is also the closest to how I would do it, hence the problem with tests.

It's the best ways because it is my way and it adds all the little details that I expected to see but the question didn't actually specify.

Answer C#

    protected Boolean LoadDataAnswer1(String strConnectionStringLocal,DataTable dtInteresting)
        Boolean boolRes = false;
        String strSQL;
        SqlConnection connSQL;
        SqlCommand cmdSQL;
        SqlDataReader drSQL;

            // Load the datatable with the relevant tickers
            using (connSQL = new SqlConnection(strConnectionStringLocal))
            using (cmdSQL = new SqlCommand())
                // Main Select
                strSQL = "[spSelect tab_StockTickers1]";
                cmdSQL.Connection = connSQL;
                cmdSQL.CommandText = strSQL;
                cmdSQL.CommandType = CommandType.StoredProcedure;
                cmdSQL.CommandTimeout = 3600;
                cmdSQL.Parameters.AddWithValue("@ShareIndex", "FTSE 100");

                // Create a datatable for the results
                dtInteresting = new DataTable();

                // Load datatable from an SQL Datareader
                using (drSQL = cmdSQL.ExecuteReader())
            boolRes = true;
        catch (Exception ex)
        return boolRes;

Answer SQL

USE StockTickers

IF OBJECT_ID('spSelect tab_StockTickers1') IS NOT NULL DROP PROCEDURE [spSelect tab_StockTickers1]

Selects core information about a company and its stock market details

1.00    Ian Smith   26/Jun/2020 Original
CREATE PROCEDURE [spSelect tab_StockTickers1]
@ShareIndex VARCHAR(32)

SELECT Company,
  FROM StockTickers
WHERE ShareIndex = @ShareIndex 

Other Interesting Pages On Some Of My Sites.
Car Insurance Premiums Explained
Generic car picture Car Insurance Premiums Explained This site aims to explain how car insurance premiums are usually calculated in response to repeated questions on various internet fora such as;

I added my mum as a driver and the premium went down.Why is someone quoting £300 and someone else £1200? Why is my renewal premium higher than my first year's premium?
Buy A Ghost
Picture of a cat with yellow star Buy A Ghost is a light hearted source of one page ghost stories aimed at pubs and restaurants as talking points.

Print them off and put them on the tables or walls and you have an instant talking point.

Aimed at regulars who have run out of things to say or new groups or couples as an ice-breaker.
Weight Loss Calculator
Screen shot of weight loss calculator Weight Loss Calculator Tries to simulate the body and report the effects of food and exercise in periods as short as 15 minutes.

This level of detail highlights the effects of a run, bike ride or chocolate bar.

For those who are new to exercise, weight fluctuation due to glycogen usage is made much clearer.
Please note that these links do not use any tracking cookies or similar technology.