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.pro c_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(Comma ndType.Text,"Select
@@Identity"));
log.Debug("Id is:"+id);
.....
....
....