how to generate auto generated number in

Posted by Venky.Net under ASP.NET on 4/5/2014 | Points: 10 | Views : 860 | Status : [Member] | Replies : 2
hi i am doing auto generated number for particular column in sql table with c# code


05/04/2014/00001 this is my auto id for first time.this id save to database
Next time i am putting the value to same page i want output like this 05/04/2014/00002
please give problem solution.


Posted by: Pawansoftit on: 4/6/2014 [Member] Starter | Points: 25

Hai Venky,
As you have mentioned that the auto id is not the integer which should be generated automatically from the database side.
You need to make it as string in the Database.If you still want it to be integer then you need to store only the second part of your auto generated id i.e. 000001 or 000002 something like that.And then the other column should have the first part which looks like the current date and can be stored in the database as date column.
When retrieving, you just get the last part of the id, incremented by 1 and then append the current date and display to the user.
While saving, you just need to second part and store the current date in the second column which was date column.
by this way,you should be able to achieve your result.
Also I am not sure if you know that you will be storing only 1,2,3...and not 0000001,000002,000003 etc in the database. This is formatted string which you need to get in your .net code by formatting of ToString function.
Hope it will be helpful to you.

Pawan Awasthi
+91 8008482352

Venky.Net, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Antonydurai on: 4/9/2014 [Member] Starter | Points: 25

Hi Venky,

try this code. Hope it will be help to you.

var PreNumber = "05/04/2014/00001";
var num = PreNumber.Substring(11);
var NextNumber = Convert.ToInt32(num) + 1;
var s = DateTime.Today.Day.ToString("00") + "/" + DateTime.Today.Month.ToString("00") + "/" + DateTime.Today.Year.ToString("0000") + "/" + NextNumber.ToString("00000");
Console.WriteLine("Next Value: {0}", s);

Venky.Net, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response