Enteprise Library Data Access @@Identity

L

Liming

Hello all,

I have a need to use "select @@identity" to get the auto id on the row
that I just inserted. But for some reason, I always get back 0. I used
MS Access. Please advice.

Database InvestmentsDb = DatabaseFactory.CreateDatabase( "Investments"
);
using (IDbConnection connection = InvestmentsDb.GetConnection())
{
connection.Open();
IDbTransaction transaction = connection.BeginTransaction();
try{

DBCommandWrapper Proc_Login_Insert =
InvestmentsDb.GetStoredProcCommandWrapper(this.proc_Logins_Insert); Proc_Login_Insert.AddInParameter("@UserName",
DbType.String,
this.userName); Proc_Login_Insert.AddInParameter("@Password",
DbType.String,
this.password); Proc_Login_Insert.AddInParameter("@Email",
DbType.String, this.email);
Proc_Login_Insert.AddInParameter("@RoleType", DbType.String,
"investor");
InvestmentsDb.ExecuteNonQuery(Proc_Login_Insert, transaction);

String id = "";
id =
Convert.ToString(InvestmentsDb.ExecuteScalar(CommandType.Text,"Select
@@Identity"));
log.Debug("Id is:"+id);
.....
....
....
 
L

Liming

never mind. my ExecuteScale wasn't part of the transaction and i added
it in, it works
 
R

rviray

forgive my ignorance, I am not an Access guru...however, I have onl
used @@Identity in store procs right after I run the inser
statement...also, "Select @@Identiy" <-- how does it know which tabl
your talking about?

Anyway, why couldn't you run a select statement (after your inser
statement) like "Select top 1 idColumn from tbl order by idColumn desc
(once again, I don't know if Access has a "TOP" keyword...)

Sorry I couldn't be more help..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top