How to insert a value into a database in sql with python language?

1
from query import PzasOP14

ns = event.source.parent.getComponent('NoDeSerie').text
pok= event.source.parent.getComponent('PzaOk').text
pnk= event.source.parent.getComponent('PzaOk').text
tc = event.source.parent.getComponent('TiempoCiclo').text
cb = event.source.parent.getComponent('CodigoDeBarras').text
mdl= event.source.parent.getComponent('Modelo').text
trn= event.source.parent.getComponent('Turno').text


query = " INSERT INTO [dbo].[PzasOp14] (NoDeSerie, PzaOk, PzaNok, TiempoCiclo, CodigoDeBarras, Modelo, Turno) VALUES (?,?,?,?,?,?,?)"
args = [006,1,0,200,1365411,541,654]
system.db.runPrepUpdate(query,args)

I have a table where I can enter the serial number, cycle time and barcode data, but when I do the python script, it does not insert anything and I see them:

  

Traceback (most recent call last): File "", line 1, in    ImportError: No module named query

    
asked by Julio C. Reyes 31.10.2018 в 18:33
source

1 answer

0

In the first line of your script, you make an import:

from query import PzasOP14

For this to work, the query.py module must exist, which in turn must declare the function PzasOP14

The error message indicates that the system is unable to find the file query.py , required by your script.

The search is done between the default modules of phyton, and in the folders defined in the variable sys.path . Maybe the fault is that this variable is not well initialized.

More information in the modules (in English) documentation.

    
answered by 31.10.2018 в 18:47