CJSantora
asked on
An object reference is required for the nonstatic field, method
I am a novice at C# and I am getting an error when trying to call a subroutine:
~\Class1.cs(37): An object reference is required for the nonstatic field, method, or property 'VinExplosion.Class1.updat eDB()'
code:
static void Main(string[] args)
{
// QUERY DATABASE AND CREATE CSV FILE
// queryDB(); ~~~~ REMOVE TO EXECUTE
// EXECUTE APPLICATION
// PASRE DATA AND UPDATE DATABASE
updateDB(); ~~~~~~~~~~~~~~~~~~~~ ERROR ON THIS LINE
}
void updateDB()
{
// READ CSV FILE AND UPDATE DATABASE
FileStream file = new FileStream("C:\\TEMP\\OUTP UT.csv", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
Console.Write(s);
sr.Close();
file.Close();
}
I would appreciate any advice, I am sure that it is syntax or something simple..
Thank You
CJSantora
~\Class1.cs(37): An object reference is required for the nonstatic field, method, or property 'VinExplosion.Class1.updat
code:
static void Main(string[] args)
{
// QUERY DATABASE AND CREATE CSV FILE
// queryDB(); ~~~~ REMOVE TO EXECUTE
// EXECUTE APPLICATION
// PASRE DATA AND UPDATE DATABASE
updateDB(); ~~~~~~~~~~~~~~~~~~~~ ERROR ON THIS LINE
}
void updateDB()
{
// READ CSV FILE AND UPDATE DATABASE
FileStream file = new FileStream("C:\\TEMP\\OUTP
StreamReader sr = new StreamReader(file);
string s = sr.ReadToEnd();
Console.Write(s);
sr.Close();
file.Close();
}
I would appreciate any advice, I am sure that it is syntax or something simple..
Thank You
CJSantora
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and just to complete the above, you can either have it static or add an instance of you class:
So, if you still have your default name Class1, it will be:
[STAThread]
static void Main(string[] args)
{
Class1 c1 = new Class1();
c1.Test();
}
and everything will compil and run just fine.
regards,
yurich
So, if you still have your default name Class1, it will be:
[STAThread]
static void Main(string[] args)
{
Class1 c1 = new Class1();
c1.Test();
}
and everything will compil and run just fine.
regards,
yurich
replace with:
static void updateDB()