hi guys,
i am using ms access 2003 database
and i want to generate different employee id's
like for manager starts from mm0001
and increasing automatically by one
and for consultant starts from mc00001
and increasing by one automatically on registration of new consultant
plz help me how to do this
Loading
Sam HobbsPosted May 2, 2011, 7:16 PM
As in Kirtan's pseudocode, you can query the table to determine what is the highest value in the table currently. Note that you would need to use something like a "like" in the query so you get a different result depending on whether it is for a manager or a consultant or whatever. Also note that you probably don't want to use Convert.ToInt32 to convert the new id to text, since if you do you would get results such as mm1 and mc1 instead of mm0001 and mc0001, correct?
Alternatively, you can create a different table that is just for creating new ids. In the table, there could be one row for each type of person; for a manager or a consultant or whatever. Then just read and write each row as needed.
There are other possibilities. If you really wanted to, you could just store the maximum id values in a file.
Kirtan PatelPosted May 2, 2011, 4:36 AM
genrate id as percondition using code
string id = ""
if ( manager)
{
string max = retrive last id from database / AppSetting
max = max.replace("mm");
int lastmax_id = Convert.ToInt32(max);
id+="mm"+(lastmax_id+1).ToString();
}
else if(consultant)
{
/* Do same thing as done in case of manager */
}
additinally you can add 0's in your id if integer is not of desire length its just simple String operation that you can perform at your own