c# - SELECT @@IDENTITY in Access always returning 0 -
i have been trying find solution problem far nil worked.
private void insert() { string connectionstringaccess = provider=microsoft.ace.oledb.12.0;data source=###jet oledb:database password=###; string query2 = "select @@identity"; int id = -1; string query = "insert tbltable (empno, name) values (132, 'testname');"; oledbconnection con = new oledbconnection(connectionstringaccess); oledbcommand cmd = new oledbcommand(query, con); seek { con.open(); if (cmd.executenonquery() == 1)//the insert succeded { cmd.commandtext = query2; id = convert.toint32(cmd.executescalar()); } } grab (exception ex) { //log ex } { con.dispose(); con.close(); } } each time utilize above method homecoming of 0 in "id". doing wrong? tried using different connection string or way latest identifier:
provider=microsoft.jet.oledb.4.0; scope_identity()but 1 time again nothing. access db 2003 or older (not sure exactly).
the ms access db 2003 or older (not sure exactly)
i able recreate issue access 97 database. select @@identity worked correctly access 2000 database file (even when run same oledbcommand object insert), returned 0 when run against access 97 database.
it appears need upgrade database file newer version if want select @@identity work.
c# asp.net ms-access oledb ado
No comments:
Post a Comment