Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8279505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:22:12+00:00 2026-06-08T09:22:12+00:00

I built a console application and I’m trying to test if my application works

  • 0

I built a console application and I’m trying to test if my application works as expected.
I create an instance of the API class as shown in the code below but I receive an error:
An object reference is required for the non-static field. I’ve already checked similar issues like this one but it seems different. What am I doing wrong?

namespace ConsoleApplication1
{
    class Api
    {

        String ConStr = "SERVER=myservername; Database=mydb; UID=mylogin; PWD=mypassword;encrypt=no;enlist=false";
        String bin_Num = "201284-11-000";
        Label lblResults;

        static void Main(string[] args)
        {
            Api Test_api = new Api();
            Test_api.getQualWeight(ConStr, bin_Num, lblResults);
        }

        public Dictionary<String, String> getQualWeight(String sqlConStr, String inBin, Label lblResults)
        {
            Dictionary<String, String> qualList = new Dictionary<string, string>();
            string selectSQL = "select Name,qual_weight from Qualification_type "
                             + "where ID in (select Qualification_ID from Qualifications where BIN = @inBin)";
            con = getConn(sqlConStr);
            SqlCommand cmd = new SqlCommand(selectSQL, con);
            cmd.Parameters.AddWithValue("@inBin", inBin);
            SqlDataReader reader;

            try
            {
                con.Open();
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    qualList.Add(reader[0].ToString(), reader[1].ToString());
                }
                reader.Close();
                return qualList;
            }
            catch (Exception err)
            {
                lblResults.Text = "error fetching qualification weight " + err.Message;
                return null;
            }
            finally
            {
                con.Close();
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T09:22:13+00:00Added an answer on June 8, 2026 at 9:22 am

    If you want to use an Object and not have all the members be static you need to reference the non-static member variables using an instance of the class.

    Change:

    Test_api.getQualWeight(ConStr, bin_Num, lblResults);
    

    To:

    Test_api.getQualWeight(Test_api.ConStr, Test_api.bin_Num, Test_api.lblResults);
    

    Because ConStr, bin_Num, and lblResults are instance variables they must be references with an instance of the class – in this case Test_api.

    Alternately, you could move those values into a global, static, scope by changing their declarations from:

    String ConStr = "SERVER=myservername; Database=mydb; UID=mylogin; PWD=mypassword;encrypt=no;enlist=false";
    String bin_Num = "201284-11-000";
    Label lblResults;
    

    To this:

    static String ConStr = "SERVER=myservername; Database=mydb; UID=mylogin; PWD=mypassword;encrypt=no;enlist=false";
    static String bin_Num = "201284-11-000";
    static Label lblResults;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I built a console application and built the solution, taking over the API to
I have built a console application that works okay when it references a .exe
I'm trying to create an extensible utility console application in .NET 4, and I
I've created a simple console Java application that is built with Maven. Is there
I'm running a .NET remoting application built using .NET 2.0. It is a console
I built a little console application in C# and need to add a windows
My program (a console application) references several other assemblies (many open-source libraries). I built
In a small console application I'm writing to test something I need to add
Today I experienced a weird problem while trying to remotely debug an application built
I've built a .NET console application which worked fine for several years. Since November

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.