不可调用的成员'DetailsForm.cmd'不能像方法一样使用

时间:2017-12-18 13:52:55

标签: c# sql visual-studio sqlcommand

我试图让命令工作,但它没有工作帮助请。此错误出现在cmd(“删除

我有sqlcommand cmd;

#mqttbroker.py
def onMessage(self, callback):
        self.client.on_message = callback
        self.client.loop_forever()

#database.py
def on_message(self,client,userdata, msg)
    #store messsages in db

#main.py
import mqqtbroker
import database

client = mqqtbroker()
client.connect(host, port, 60)
client.onMessage(database.on_message)

1 个答案:

答案 0 :(得分:2)

这一行:

cmd("delete blacklist1 where idnumber=@Idnumber", con);

应该是:

cmd = new SqlCommand("delete blacklist1 where idnumber=@Idnumber", con);

但是,您应该将其放在using块中,以便在完成后释放cmd资源。请参阅:SqlCommand with using statement