我上课的经验有限,所以我很抱歉。我有一个数据库类。我创建了它的一个实例,并尝试通过它运行SQL函数,这些函数可以正常工作,直到我需要用conn.commit()
保存一个INSERT到。我的代码是follows:- 你知道吗
Class DatabaseClass():
def __init__(self):
self.open_database()
def open_database(self):
conn = pyodbc.connect(
r"Driver={SQL Server};"
r"Server=ServerName;"
r"Database=DatabaseName;"
r"Trusted_Connection=yes;"
)
self.cursor = conn.cursor()
def NewRecord()
self.cursor.execute ("INSERT INTO ....")
self.conn.commit()
db = DatabaseClass()
db.NewRecord()
但我得到了错误
"DatabaseClass object has no attribute 'conn'".
我该怎么做才能让NewRecord
函数知道它处理的是什么连接
谢谢
目前没有回答
相关问题 更多 >
编程相关推荐