Enterprise Library select @@identity

  • Thread starter Thread starter Liming
  • Start date Start date
L

Liming

Hello all,

I have a need to use "select @@identity" to get the autoid on the row
that I just inserted. The insert store procedure executed correctly as
if I took out the transaction, i can see the row being inserted. I just
can't get back the id that's all. I use MS ACCESS btw (using a third
party oledb add on, not sure if that's why it's causing problem)


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);
 
nevermind. my ExecularScalar method, wasn't part of the transaction, i
added the transaction object in and i'm in bussiness. thanks.
 

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


Back
Top