A
ashtek
Hi,
I am working on an ASP.NET application where I need to create a unique
key in a page. When a customer clicks on the button "Generate Key" I
need to create a key which should be unique in the database. I am
plannig to create in the format MMDDYYHHMMSS.
I have written a class that generates the key:
public class GenUniqueID
{
private static readonly GenUniqueID instUnique=new GenUniqueID();
private StringBuilder strUnique=new StringBuilder("");
private GenUniqueID()
{
DateTime dtID=DateTime.Now;
strUnique.Append(dtID.Month);
strUnique.Append(dtID.Day);
strUnique.Append((dtID.Year.ToString()).Substring(2,2));
strUnique.Append(dtID.Hour);
strUnique.Append(dtID.Minute);
strUnique.Append(dtID.Second);
}
public static GenUniqueID Instance
{
return instUnique;
}
public static string UniqueID
{
get
{
return strUnique.ToString();
}
}
}
I'll call this method from my aspx page :
GenUniqueID key=GenUniqueID.Instance();
string strKey=key.UniqueID;
Will this guarantee a UNIQUE key even if two or more users from
different locations will click on "Generate Key" at the same time???
Thanks,
Ashish.
I am working on an ASP.NET application where I need to create a unique
key in a page. When a customer clicks on the button "Generate Key" I
need to create a key which should be unique in the database. I am
plannig to create in the format MMDDYYHHMMSS.
I have written a class that generates the key:
public class GenUniqueID
{
private static readonly GenUniqueID instUnique=new GenUniqueID();
private StringBuilder strUnique=new StringBuilder("");
private GenUniqueID()
{
DateTime dtID=DateTime.Now;
strUnique.Append(dtID.Month);
strUnique.Append(dtID.Day);
strUnique.Append((dtID.Year.ToString()).Substring(2,2));
strUnique.Append(dtID.Hour);
strUnique.Append(dtID.Minute);
strUnique.Append(dtID.Second);
}
public static GenUniqueID Instance
{
return instUnique;
}
public static string UniqueID
{
get
{
return strUnique.ToString();
}
}
}
I'll call this method from my aspx page :
GenUniqueID key=GenUniqueID.Instance();
string strKey=key.UniqueID;
Will this guarantee a UNIQUE key even if two or more users from
different locations will click on "Generate Key" at the same time???
Thanks,
Ashish.