获取ACCESS数据库中自增变量的值
/// <summary> /// 获取自增变量值 /// </summary> /// <returns>自增变量值</returns> public int getReturnIdentity() { //Conn_Open(); string strCMDtext = @"select @@identity"; OleDbCommand cmd_sql = new OleDbCommand(strCMDtext, conn_1); int i = int.Parse(cmd_sql.ExecuteScalar().ToString()); cmd_sql.Dispose(); return i; //conn_close(); }
sCon = System.Configuration.ConfigurationManager.ConnectionStrings["access"].ConnectionString;
con = new OleDbConnection(sCon);
con.Open();
int i = -1;
OleDbCommand cmd = con.CreateCommand();
OleDbTransaction tr = con.BeginTransaction();
cmd.Transaction = tr;
cmd.CommandText = …………;
try
{
i = cmd.ExecuteNonQuery();
if (i > 0)
{
cmd.CommandText = @"select @@identity";
i = int.Parse(cmd.ExecuteScalar().ToString());
}
tr.Commit();
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
this.Close();
return i;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。