tags:

views:

377

answers:

3

I have table called emp. The table contains three columns empid, ename and salary. I have to store the empid as autogenerated ids, for example: E001, E002, E003. How can I do that using C#?

+1  A: 

You could use an autoincremented int column and add the "E" prefix for display purposes only.

Marcelo Cantos
thanks, i tried it. but it doesn't works
sameer
What doesn't work, exactly? Are you not sure how to create an autoincrement field, or do you not know how to present an integer field as a prefixed string on some UI?
Marcelo Cantos
+1  A: 
stakx
thanks for the help, can you give some example code?
sameer
Added some code examples. You should be able to piece them together yourself. (Sorry for being so cautious, this still smells like homework and I actually feel that I've already provided too much concrete code.)
stakx
A: 

This my answer,

public string GetLatestOrderId()
        {
            string ReceivedId = string.Empty;
            string displayString = string.Empty;
            String query = "SELECT MAX(OrderReceivedNo) FROM [Order_Received]";
            String data = DataManager.RunExecuteScalar(ConnectionString.Constr, query);
            ReceivedId = data;
            if (string.IsNullOrEmpty(ReceivedId))
            {
                ReceivedId = "OR0000";//It is the start index of alpha numeric value
            }
            int len = ReceivedId.Length;
            string splitNo = ReceivedId.Substring(2, len - 2);//This line will ignore the string values and read only the numeric values
            int num = Convert.ToInt32(splitNo);
            num++;// Increment the numeric value
            displayString = ReceivedId.Substring(0, 2) + num.ToString("0000");//Concatenate the string value and the numeric value after the increment
            return displayString;
        }
sameer
@sameer: learn how to use the code button to make your posts comprehensible.
David-W-Fenton