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#?
views:
377answers:
3
+1
A:
You could use an autoincremented int column and add the "E" prefix for display purposes only.
Marcelo Cantos
2010-04-03 09:52:14
thanks, i tried it. but it doesn't works
sameer
2010-04-03 10:20:03
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
2010-04-04 01:30:49
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
2010-04-03 13:01:21
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
2010-08-18 09:00:23
@sameer: learn how to use the code button to make your posts comprehensible.
David-W-Fenton
2010-08-18 23:53:34