sql - Getting the Last Insert ID with SQLite.NET in C# -


i have simple problem not simple solution... inserting data database this:

                kompenzacijedataset.kompenzacijerow kompenzacija = kompenzacijedataset.kompenzacije.newkompenzacijerow();                 kompenzacija.datum = datetime.now;                 kompenzacija.podjetjeid = stranka.id;                 kompenzacija.znesek = decimal.parse(tbznesek.text);                  kompenzacijedataset.kompenzacije.rows.add(kompenzacija);                  kompenzacijedatasettableadapters.kompenzacijetableadapter kompta = new kompenzacijedatasettableadapters.kompenzacijetableadapter();                 kompta.update(this.kompenzacijedataset.kompenzacije);                  this.currentkompenzacijaid = lastinsertid(kompta.connection); 

the last line important. why supply connection? there sqlite function called last_insert_rowid() can call , last insert id. problem is bound connection , .net seems reopening , closing connections every dataset operation. thought getting connection table adapter change things. doesn't.

would know how solve this? maybe constant connection from? or maybe more elegant?

thank you.

edit:

this problem transactions, need same connection if want use transactions, problem...

select last_insert_rowid(); 

and need execute scalar query.

string sql = @"select last_insert_rowid()"; long lastid = (long)command.executescalar(sql); // need type-cast since `executescalar` returns object. 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -