SQLite & AUTOINCREMENT

alocin

Member
Joined
Jul 20, 2004
Messages
5
Im trying to use SQLite iwith c#, the autoincreement attribute for a field in primary key seems not working properly :-\

the code is

//Globals
SQLiteClient db;

//.....creating table
db.Execute("CREATE TABLE tblProva (id INT AUTOINCREMENT ,name VARCHAR( 255 ) NOT NULL ,PRIMARY KEY ( id ) ) ");

//.....inserting row
db.Execute("INSERT INTO tblProva (nome) VALUES (ciao)");

//..then the select
SQLiteResultSet results;
results = db.Execute("SELECT * FROM tblProva ");
foreach (ArrayList arr in results.Rows)
{
foreach(object j in arr)
Console.Write("\t" + Convert.ToString(j) );
Console.WriteLine();
}

//but it doesnt insert an autoincrement INT into id field!! :confused: , theres undefined value instead... can u help me?
 
If you would have taken a look in the SQLite manual you would have seen,
that an autoincrement column is created with

db.Execute("CREATE TABLE tblProva (id INTEGER PRIMARY KEY,name VARCHAR( 255 ) NOT NULL) ");
 
Back
Top