在静态方法中调用存储过程 [英] calling stored procedure in static method

查看:78
本文介绍了在静态方法中调用存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在此函数中调用存储过程

称为Jobs.cs的类

how to call stored procedure in this function

a class called Jobs.cs


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

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



我想在(DailyJob)函数中调用过程,而这是我在调用过程DailyJob时出现的错误:



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);

推荐答案

这没关系,它是一个静态方法-可以像往常一样进行操作.
It doesn''t matter that it''s a static method - do it the same way you normally would.


代码的问题是,您试图从静态方法访问非静态字段或方法或属性.之所以无法这样做,是因为可以在不实例化该类型的对象的情况下调用静态方法,因此无法依赖实例字段,方法或属性.

如果没有理由将您的方法设为静态,那么我建议您从方法定义中删除该关键字.如果由于某种原因不能执行此操作,则只能在静态方法DailyJob中使用局部变量和类的静态字段,方法和属性.


最好的问候,
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,


这篇关于在静态方法中调用存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆