G
Guest
I need some help on solving a simple problem that I just cannot figure out.
Task: Generate an ID based on the year, millisecond, second like
Y2004MS456S31. Use this ID has a unique name for an object in conjunction
with a SQL IDENTITY column.
Problem: Since there are no guarantees that this will not be duplicated, I
must check to see if it exists before I use one that is created. Even though
there will only likely be a couple hundred max objects requiring a name I
cannot have any named the same.
Current Process: 2 functions within an object. (pseudo code)
public string GenerateID() {
string returnvalue;
Use stringbuilder to build ID from date/time;
if (VerifyID(returnvalue)) {
GenerateID();
}
else
{
return returnvalue;
}
}
private bool VerifyID(string tempID) {
Check Database to see if tempID exists.
If it does return true
else
return false
}
As you can see GenerateID will not compile because all code paths do not
have a return value. Can someone give me suggestions how I can generate the
id, check its existence in the database, if it exists duplicate the process,
if it doesn't exist return the value.
Thanks
Task: Generate an ID based on the year, millisecond, second like
Y2004MS456S31. Use this ID has a unique name for an object in conjunction
with a SQL IDENTITY column.
Problem: Since there are no guarantees that this will not be duplicated, I
must check to see if it exists before I use one that is created. Even though
there will only likely be a couple hundred max objects requiring a name I
cannot have any named the same.
Current Process: 2 functions within an object. (pseudo code)
public string GenerateID() {
string returnvalue;
Use stringbuilder to build ID from date/time;
if (VerifyID(returnvalue)) {
GenerateID();
}
else
{
return returnvalue;
}
}
private bool VerifyID(string tempID) {
Check Database to see if tempID exists.
If it does return true
else
return false
}
As you can see GenerateID will not compile because all code paths do not
have a return value. Can someone give me suggestions how I can generate the
id, check its existence in the database, if it exists duplicate the process,
if it doesn't exist return the value.
Thanks