获取唯一标识的几种方法
一 、 写序列
数据库创建
–** 创建流程ID序列
create sequence NURADM.NURADM_FLOW_SEQ
increment by 1//增长值
start with 1//起始值
nomaxvalue//最大值可以不写
nominvalue
nocache;
create public synonym NURADM_FLOW_SEQ for NURADM.NURADM_FLOW_SEQ;//需要创建同义词
c#
using TJHIS.Comm;
private DBSrv ws = new DBSrv();
///
/// 获取流程配置ID(序列)
///
///
public int GetFlowConfigID()
{
int csNo = ws.GetSeq(“NURADM_FLOW_SEQ”); //流程配置ID数据库序列
return csNo;
}
二 、 使用时间戳
using System;
//获取当前时间戳,理论上精确到毫秒时,不会有重复的数据
public string GetTimeStamp()
{
Random ran = new Random();
int RandKey = ran.Next(100, 1000);
DateTime dtNow = DateTime.Now;
return dtNow.ToString(“yyMMddHHmmss”) + dtNow.Millisecond.ToString() + RandKey.ToString();
}
三 、以实际数据库中的最大值做累加
///
/// 获取TYPE_ID的最大值并加1
///
///
public string ReturnMaxTypeId()
{
string typeid = string.Empty;
int int_type = 1000;
string sql = “select max(type_id) type_id from nr_SEVERE_type”;
DataSet ds = dbConn.SelectData(sql,true);
if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0][“type_id”].ToString().Trim().Trim().Length > 0)
{
int_type = Convert.ToInt32(ds.Tables[0].Rows[0][“type_id”].ToString()) + 1;
}
else
{
int_type = 1;
}
typeid = string.Format(“{0:00}”, int_type);
return typeid;
}