Android Question Not autoincrement primary key

ivavilagu

Member
Licensed User
I created a DB with the "DB Browser for SQLite" software. At the picture attached you can see two tables with their primary keys fields.

If I insert a new register, the ID primary key field keeps empty

B4X:
SQL1.ExecNonQuery2("INSERT INTO referencia VALUES(null,?,?,?)", Array As Object(txtREFERENCIA.Text, txtMAQUINA.text, txtPUESTO.Text))

For i =0 To lstMOVIMIENTOS.Size - 1
SQL1.ExecNonQuery2("INSERT INTO movimientos VALUES(null,?,?,?)", Array As Object(1,  lstMOVIMIENTOS.GetItem(i), lstTMTP.GetItem(i)))
Next
 

Attachments

ivavilagu

Member
Licensed User
Hello,
My first column in all my databases (SQLite, MySQL, MSSQL etc) is called id. In SQLite it would be created as follows, thus the id column will always auto increment.
B4X:
[id] INTEGER  PRIMARY KEY AUTOINCREMENT NOT NULL,
I don´t think it´s a naming problem, but I´m not sure .
 

ivavilagu

Member
Licensed User
I didn't say that it was. I was just saying that the above line is mandatory in all my databases and it works perfect, so just add AUTOINCREMENT NOT NULL and give it a go :)
Ups, Ok. The problem is that I had created the table with a external software. Is it possible to determine the primary key once the table has been created before?
 

ivavilagu

Member
Licensed User
Thank you!! you`re agree. In the software there is an autoincrement option, a little bit hidden but it´s works perfectly.

Thank you again man!
 
Top