How to insert dataset to a databse


I would like to insert a dataset (shown below with 2 rows and 10 columns) into a database but I am not how to do this!
I have tried this script but it is not working:

	data=										#sample Dataset [12R ? 10C]
	pds = system.dataset.toPyDataSet(data)										#sample <PyDataset rows:12 cols:10>
	for index in range(len(pds)):
	system.db.runPrepUpdate("INSERT INTO testdatabase (v1,v2,v3,v4,v5,v6,v7,v8,v9,v10) VALUES (?,?,?,?,?,?,?,?,?,?)", rowData)

The dataset table (2 rows and 10 columns):

I greatly appreciate any information you could share with me.

I’m guessing it’s only inserting the last row? Indent the runPrepUpdate to be inside the loop.

1 Like

One thing I forgot to mention: Since this script will run on the gateway (because you’re using perspective), you will need to specify the db connection.

1 Like

Thank you very much, Jordan! That worked :slight_smile:
Appreciate it!