Hi ive created this code for search and when i debug the applicaion it gives me an error with Variables, I dont understand a thing about variables, ive searched for a chapter on variables but i cant seem to find it on line, if any1 knows wer i can find any good C# books online for free please help me with the link.

Error 1 An object reference is required for the nonstatic field, method, or property 'Variables.client_ID'
Error 2 Operator '==' cannot be applied to operands of type 'string' and 'int'.
Error 3 An object reference is required for the nonstatic field, method, or property 'Variables.client_ID'
Error 4 An object reference is required for the nonstatic field, method, or property 'Variables.client_ID'
Error 5 'Call_login.Client' does not contain a definition for 'client_IDLabel_Click'

private void searchBtn_Click(object sender, EventArgs e)
            string client_ID = "";
            string tittle = "";
            string client_f_name = "";
            string client_l_name = "";
            string technician_ID = "";
            string item_name = "";
            string status = "";
            string email = "";
            string tel_no = "";
            string extension_no = "";
            string serial_no = "";
            string call_no = "";
            string address = "";
            string date_assigned = "";
            string office_no = "";

            Client pp = new Client();

            //int client_ID = Variables.client_ID;

            [U]if (Variables.client_ID == 0)[/U]
                client_IDTextBox.Text = "" + client_ID;


                    OleDbConnection conn = new OleDbConnection(@"provider = Microsoft.Jet.OLEDB.4.0;Data Source= C:\Documents and Settings\Developers ITD\My Documents\Visual Studio 2005\Projects\Call_login\Call_login\call login.mdb");

                    OleDbCommand commander = new OleDbCommand(
                        "SELECT CLIENT_ID, tittle, client_f_name, client_l_name, technician_ID, ITEM_NAME, STATUS, EMAIL, TEL_NO, EXTENSION_NO, SERIAL_NO, CALL_NO, ADDRESS, date_Assigned, OFFICE_NO = '" + Variables.client_ID + "'", conn);
                    commander.CommandType = CommandType.Text;
                    OleDbDataReader reader = commander.ExecuteReader();

                    if (reader.Read())
                        client_ID = (reader.GetString(0));
                        tittle = (reader.GetString(1));
                        client_f_name = (reader.GetString(2));
                        client_l_name = (reader.GetString(3));
                        technician_ID = (reader.GetString(4));
                        item_name = (reader.GetString(5));
                        status = (reader.GetString(6));
                        email = (reader.GetString(7));
                        tel_no = (reader.GetString(8));
                        extension_no = (reader.GetString(9));
                        serial_no = (reader.GetString(10));
                        call_no = (reader.GetString(11));
                        address = (reader.GetString(12));
                        date_assigned = (reader.GetString(13));
                        office_no = (reader.GetString(14));

                    client_IDTextBox.Text = client_ID;
                    tittleTextBox.Text = tittle;
                    client_f_NameTextBox.Text = client_f_name;
                    client_l_NameTextBox.Text = client_l_name;
                    technician_IDTextBox.Text = technician_ID;
                    item_NameTextBox.Text = item_name;
                    statusTextBox.Text = status;
                    emailTextBox.Text = email;
                    tel_NoTextBox.Text = tel_no;
                    extension_NoTextBox.Text = extension_no;
                    serial_NoTextBox.Text = serial_no;
                    call_NoTextBox.Text = call_no;
                    addressTextBox.Text = address;
                    date_AssignedDateTimePicker.Text = date_assigned;
                    client_IDTextBox.Text = "" +[U] Variables.client_ID[/U];


Edited 6 Years Ago by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

Firstly, please use code tags when posting code: [code] Code goes in here [/code].
Secondly, where did you get your code? If you dont know what a variable is i'm going to assume you have never coded before.
Its the line 'Variables.client_ID' that is causing most of your errors. You are trying to access the client_ID member/method of an object that you havent instantiated. In other words, the complier doesnt know what Variables actually is. Although, i find it hard to believe you couyldnt find anything online about variables!

No ive read about variables and what i read doesnt actualy explain what variables are. and yes ive never coded this is my first project ive just been reading a few online c# books. from what i read i tried creating varibles and i still got errors.

Edited 6 Years Ago by badx: n/a

Ok, the use of Variables as an object name seems to be causing some confusion. A variable is a named space in memory used to store a value. You declare it like so:

//<type> <name> [optional assignment]
int myInt = 2;

This sets aside a space in memory large enough to store an integer value and gives it a name (in the example 'myInt'). You can then access that value using its name.

Objects of different types have different members which can be accessed. For instance:

//declare a variable of type string called myString and assign it a value of "Hello World"
string myString = "Hello World";

//one of the methods exposed by the string type is ToLower which returns its value covnerted to lower case
//we access members of an object using a '.'

//i declare a new string to store the result. Then i assign it the value returned by the ToLower method.
//because its a method it has '()' after it. Some methods will have parameters inside these brackets.
string myLowerString = myString.ToLower()

In your code, Variables is the name of an object. It is a variable called Variables. The errors you are getting are caused by the fact that you haven't declared it. The compiler doesnt have any record of an object called Variables so it

If i had to guess (and without seeing all of your code and the source you got it from, it really is a guess) i would say that Variables is supposed to be a static class.
A class is a more complex object, it is a wrapper that describes the members of an object. If it is declared as static (read about Static classes) then you dont have to declare it. You only ever have one copy of it and you access it by name. If you havent added the Variables class to your project, or you havent declared it as static, then you cannot access its members implicitly and Variables is no longer recognised by the compiler as a calid object reference.

As you said you are new to C# i have tried to keep this fairly simple. Apologies if it sounds patronising, or if i'm teaching you to suck eggs.

If this is your first project, i suggest you take a step back and start from the ground up. Most people begin with something simple like a Hello World console app. You've dived straight in at the deep end with database access etc.

My best recommendation would be to get a beginners book or check out a beginners website. I haven't used it, but the tutorials on functionx.com look to be well written and in depth.

But my strongest advise is "Walk before you run". If you don't know the fundamentals you will never be able to understand more advanced code. So many people on these boards try to implement code they don't understand and they end up like you, stuck and confused.
The key at each stage is to ensure you fully understand what your code does. Don't just type whats in the tutorial run it and say "It works, cool. Next page".

To paraphrase one of my favourite quotes: "Learning to code is more than absorbing syntax, it is acquiring an understanding of how and why it works" ;)

Edited 6 Years Ago by Geekitygeek: typo

To concur with Ryshad, walk before you run. Get a beginner's book, start with the standard Hello World program, and get the fundamentals down. Database programming isn't for the completely untrained novice.

This article has been dead for over six months. Start a new discussion instead.