请教,用pydboc连接数据库实现删除功能时出现的问题,数据库为sql server
这是后台代码
def VCD_info(request):
db = pyodbc.connect('DRIVER={SQL Server};SERVER=127.0.0.1;DATABASE=VCD_info;UID=sa;PWD=15036838685a;Trusted_Connection=No')
mycursor = db.cursor()
mycursor.execute("select * from VCD")
rows = mycursor.fetchall()
data = {
"VCD": rows
}
if request.method == "GET":
return render(request, 'VCD_info.html', data)
# 获取提交的数据
if 'add' in request.POST:
Vno_info = request.POST.get("Vno")
Vname_info = request.POST.get("Vname")
Actor_info = request.POST.get("Actor")
Price_info = request.POST.get("Price")
Vtype_info = request.POST.get("Vtype")
amount_info = request.POST.get("amount")
mycursor = db.cursor()
mycursor.execute("insert into VCD values (?,?,?,?,?,?)",
(Vno_info,Vname_info,Actor_info,Price_info,Vtype_info,amount_info))
db.commit()
return HttpResponse("添加成功")
elif 'del' in request.POST:
Vno_2 = request.POST.get("Vno_2")
mycursor = db.cursor()
mycursor.execute("delect from VCD where Vno=?",(Vno_2))
db.commit()
return HttpResponse("删除成功")
mycursor.close()
db.close()
这是前端代码
<div class="modal-body">
<form method="post" >
{% csrf_token %}
<p>
VCD编号:<input type="text" name="Vno_2" placeholder="请输入VCD编号">
</p>
</div>
这是报错信息
Traceback (most recent call last):
File "D:\python_path\Lib\site-packages\django\core\handlers\exception.py", line 34, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "D:\python_path\Lib\site-packages\django\core\handlers\base.py", line 126, in _get_response
response = self.process_exception_by_middleware(e, request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\python_path\Lib\site-packages\django\core\handlers\base.py", line 124, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\vscode\html文件\html学习\login\login\view.py", line 49, in VCD_info
mycursor.execute("delect from VCD where Vno=?",(Vno_2))
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]关键字 'from' 附近有
语法错误。 (156) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]无法预定义语句。 (8180)")