# Insert dataset into database

**URL:** <https://forum.inductiveautomation.com/t/insert-dataset-into-database/10563>\
**Category:** Ignition\
**Created:** [October 2, 2015, 2:08am UTC](https://forum.inductiveautomation.com/t/insert-dataset-into-database/10563 "2015-10-02T02:08:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trishhiyah](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@trishhiyah](https://forum.inductiveautomation.com/u/trishhiyah)\
**Post date:** [October 2, 2015, 2:08am UTC](https://forum.inductiveautomation.com/t/insert-dataset-into-database/10563/1 "2015-10-02T02:08:16Z")

</div>

Hi Guys, I am just new here. I need your help on how to insert the dataset to my database.  
and this is my code.[code]#  
import sys

Operator = event.source.parent.parent.getComponent(‘Container 1’).getComponent(‘lblOperator’).text  
if Operator == ‘’:  
system.gui.messageBox(“Please enter/scan valid badge ID for Operator!.”,“Invalid Badge ID”)  
sys.exit()   
Status\_ID = ‘3’  
EntryDate = event.source.parent.parent.getComponent(‘Container 1’).getComponent(‘lblDateTime’).text  
RecordID = event.source.parent.parent.RecordID  
ProgramID = event.source.parent.parent.Program  
WO\_Num = event.source.parent.parent.WO\_List  
call = system.db.createSProcCall(“usp\_Trolley\_Allocation\_Status\_History”)  
call.registerInParam(1, system.db.INTEGER, RecordID)  
call.registerInParam(2, system.db.INTEGER, Status\_ID)   
call.registerInParam(3, system.db.VARCHAR, Operator)   
call.registerInParam(4, system.db.INTEGER, ProgramID)  
call.registerInParam(5, system.db.DATA, WO\_Num)   
system.db.execSProcCall(call)

system.nav.closeWindow(‘Testing (tme)/Oven\_Tracking\_WO\_Entry\_Test’)

window = system.gui.getWindow(‘Testing (tme)/Oven\_Tracking\_Main\_Test’)  
table = window.getRootContainer().getComponent(‘Table’)  
system.db.refresh(table, “data”)

system.nav.closeParentWindow(event)

[/code]

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f025a10716f4c14c7f4f4c88c610517359700e5b.png)

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 2, 2015, 11:37am UTC](https://forum.inductiveautomation.com/t/insert-dataset-into-database/10563/2 "2015-10-02T11:37:15Z")

</div>

This looks OK. What do you want help with?

---

<div class="post-metadata">

**Author:** ![trishhiyah](https://avatars.discourse-cdn.com/v4/letter/t/9fc29f/32.png) [@trishhiyah](https://forum.inductiveautomation.com/u/trishhiyah)\
**Post date:** [October 3, 2015, 3:33am UTC](https://forum.inductiveautomation.com/t/insert-dataset-into-database/10563/3 "2015-10-03T03:33:03Z")

</div>

It has an error about inserting the Work Orders(WO) how can I insert multiple data in my database?

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [October 3, 2015, 8:38am UTC](https://forum.inductiveautomation.com/t/insert-dataset-into-database/10563/4 "2015-10-03T08:38:00Z")

</div>

That depends on how your database is set up. Assuming WO\_Num is a dataset, you will have to loop through all the values in the dataset. Your script will end up looking something like this (you’ll have to adapt it to run correctly with your stored procedure):[code]import sys

Operator = event.source.parent.parent.getComponent(‘Container 1’).getComponent(‘lblOperator’).text  
if Operator == ‘’:  
system.gui.messageBox(“Please enter/scan valid badge ID for Operator!.”,“Invalid Badge ID”)  
sys.exit()  
Status\_ID = ‘3’  
EntryDate = event.source.parent.parent.getComponent(‘Container 1’).getComponent(‘lblDateTime’).text  
RecordID = event.source.parent.parent.RecordID  
ProgramID = event.source.parent.parent.Program  
WO\_Num = event.source.parent.parent.WO\_List  
WO\_NumPy = system.dataset.toPyDataSet(WO\_Num)  
call = system.db.createSProcCall(“usp\_Trolley\_Allocation\_Status\_History”)  
call.registerInParam(1, system.db.INTEGER, RecordID)  
call.registerInParam(2, system.db.INTEGER, Status\_ID)  
call.registerInParam(3, system.db.VARCHAR, Operator)  
call.registerInParam(4, system.db.INTEGER, ProgramID)  
for row in WO\_NumPy:  
call.registerInParam(5, system.db.DATA, row[0])  
system.db.execSProcCall(call)

system.nav.closeWindow(‘Testing (tme)/Oven\_Tracking\_WO\_Entry\_Test’)

window = system.gui.getWindow(‘Testing (tme)/Oven\_Tracking\_Main\_Test’)  
table = window.getRootContainer().getComponent(‘Table’)  
system.db.refresh(table, “data”)

system.nav.closeParentWindow(event)[/code]
