Storing numbers in database

Does anyone know of any good tutorials that walks through storing numbers instead of text when adding a new row?

Anvils tutorial for storing data was great! But it’s only text. What about numbers?

You can create a column in the data tables of the number type - will that do?

Exactly the same workflow just define the column as a number column when you create it.

The value that you store will need to be a number or you will get an error

I get how to create a number column, but how do store it when adding new row to database?
In the current code i could only get .text to store in my data base. what would be the correct code to store it in a numbers column?

new_row = app_tables.audited.add_row(MonoProduced=self.MonoProduced.text)

Problem solved! just place int before and wrap in brackets!

new_row = app_tables.excel.add_row(NumberTest=int(self.numberbox.text))

You can also set the type of the TextBox to store numbers - the numberbox.text will then have a number stored and will reject any non numeric characters at input so no need to cast it to with int()

new_row = app_tables.excel.add_row(NumberTest=self.numberbox.text)

You can set this in the properties window for the TextBox

image

1 Like