Object flow of operation

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
Easyier done than said ;-)

..NET create a GUID class to create unique user id's
LIke FOllows:
Guid NewID= Guid.NewGuid();
NewID.ToString() // will generate you an id number

This will genreate a number as follows:
ae1242c1-be4d-4f50-9da9-9113b7b0a78c

You can then modify it accordingly (remove dashed, move to upper case
whatever you wish)
 
Thanks Grant but I am familiar with Guid. However, it is way too long. This
ID will actually be an identifier for the users. I don't want something that
long. The customer wants to be capable of telling the user, hey check out
publication kjkjkjj for you answer.

I just got to thinking about something. In SQL server I can do something
like Y2004PUBxx and set it to an IDENTITY column and it will automatically
increment the last digit correct?

This would be the idea solution, think I will try it.
 
Not sure about that , you can always try

Marty U. said:
Thanks Grant but I am familiar with Guid. However, it is way too long.
This
ID will actually be an identifier for the users. I don't want something
that
long. The customer wants to be capable of telling the user, hey check out
publication kjkjkjj for you answer.

I just got to thinking about something. In SQL server I can do something
like Y2004PUBxx and set it to an IDENTITY column and it will automatically
increment the last digit correct?

This would be the idea solution, think I will try it.
 
IMO don't bother and just use a number. An example of this would be the MS
KB that apparently uses 100000 to 999999

This way you have just to say hey look at 546893...

Patrice

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top