Click here to Skip to main content
15,894,907 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
how to call stored procedure in this function

a class called Jobs.cs


C#
     namespace myScheduler
{
    public sealed class Jobs
    {
        public Jobs(){}

        public static void DailyJob(object state)
        {
           //Your dream goes here.
        }
             ...
         }
         ...
      }


I want to call procedure in (DailyJob) function and this is the error when I call procedure DailyJOb:
An object reference is required for the non-static field, method, or property 'myScheduler.Jobs.con



when remove static word ..

another error
An object reference is required for the non-static field, method, or property 'myScheduler.Jobs.DailyJob(object)'

TimerCallback callbackDaily = new TimerCallback(Jobs.DailyJob);
Posted
Updated 1-Apr-11 2:41am
v5

It doesn't matter that it's a static method - do it the same way you normally would.
 
Share this answer
 
Comments
shms_rony 1-Apr-11 7:51am    
i normally writing code and work well but when i create procedure and call it ,,,give me error that this is static function
Albin Abel 1-Apr-11 7:58am    
You may be access any instance variable of the class jobs from the static method?
shms_rony 1-Apr-11 8:02am    
sorry can you write code
Albin Abel 1-Apr-11 8:13am    
Sorry I can't. I didn't thought of learn coding from your question.
shms_rony 1-Apr-11 8:15am    
this is the error when i call procedure to this method

"An object reference is required for the non-static field, method, or property 'myScheduler.Jobs.con"
The problem with your code is that you are trying to access a non static field or method or property from your static method. This cannot be done because static methods can be called without instantiating an object of that type, so relying on instance fields, methods or properties is not possible.

If there is no reason for making your method static then I'd advise you to remove that keyword from the method definition. If you can't do that for some reason, you can only use local variables and static fields, methods and properties of your class from within your static method DailyJob.


Best Regards,
 
Share this answer
 
v2
Comments
shms_rony 1-Apr-11 8:36am    
when i remove static word ..another error

"TimerCallback callbackDaily = new TimerCallback(Jobs.DailyJob);"
Albin Abel 1-Apr-11 8:42am    
Ofcourse you are passing a static method as argument (jobs.Dailyjob) which doesn't exists now. The answer already given. Static method only access static members or localized instance members. So move your objects accordingly.
Albin Abel 1-Apr-11 8:38am    
Agreed. It seems like his method access instance members. OP may need a instance method than a static method. My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900