Q:

C# method that returns a SQL string without passing any variables

I am trying to create a method that runs a query then reads the 2 values it returns then place them in the global variables so I can access them in another page. My question is what method should I use because I have two variables to set. Typically I pass the variables that I will be using but in this case I'm not. This main seem simple but I can't think of a way to get these values. I am not sure how to look this problem up to research it either. I have included the code below what I have attempted so far. Thank you for you help.
public string getTotals3()
    {
        WorkerData workerData = new WorkerData();

        StringBuilder sqlString = new StringBuilder();
        sqlString.Append("SELECT DISTINCT DataWin8Data, DataWin7Data ");
        sqlString.Append("FROM Data ");
        sqlString.Append("WHERE Number = 4");

        SqlDataReader reader = null;
        SqlConnection dbConn = App_Code.DBHelper.getConnection();

        try
        {
            reader = App_Code.DBHelper.executeQuery(dbConn, sqlString.ToString(), null);
            if (reader != null)
            {
                while (reader.Read())
                {
                    workerData.TotalCases4 = reader["DataWin8Data"] != DBNull.Value ? reader["DataWin8Data"].ToString() : string.Empty;
                    workerData.TotalPercentage4 = reader["DataWin7Data"] != DBNull.Value ? reader["DataWin7Data"].ToString() : string.Empty;
                }
            }
            else
                throw new Exception("No records returned");
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            if (dbConn != null)
            {
                try { dbConn.Close(); dbConn.Dispose(); }
                catch { }
            }
            if (reader != null)
            {
                try { reader.Close(); reader.Dispose(); }
                catch { }
            }
        }
        return workerData.ToString();
    }

A:

Don't use global variables. Return the values out of the method. The calling code should be in charge of placing those values wherever it needs. I recommend reading about Dependency Inversion Principle.
public WorkerData GetWorkerData()
{
    ...

    using (SqlDataReader reader = ...)
    {
        if (reader.Read())
        {
            return new WorkerData
                {
                    TotalCases4 = reader["DataWin8Data"] != DBNull.Value ? reader["DataWin8Data"].ToString() : string.Empty,
                    TotalCases3 = workerData.TotalPercentage4 = reader["DataWin7Data"] != DBNull.Value ? reader["DataWin7Data"].ToString() : string.Empty;
                }
        }
    }

    throw new ApplicationException("Could not retrieve worker data.");
}

From your calling class, simply do whatever you want with the return value:
WorkerData workerData = someClass.GetWorkerData();

