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
 

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

Similar Threads


Top