Click here to Skip to main content
15,888,313 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: Generate Sequential Number without database Pin
Stoffy197227-Jul-10 10:21
Stoffy197227-Jul-10 10:21 
AnswerRe: Generate Sequential Number without database Pin
David Mujica27-Jul-10 9:57
David Mujica27-Jul-10 9:57 
AnswerRe: Generate Sequential Number without database Pin
Yusuf27-Jul-10 10:22
Yusuf27-Jul-10 10:22 
GeneralRe: Generate Sequential Number without database Pin
Maikeru20002-Aug-10 5:16
Maikeru20002-Aug-10 5:16 
AnswerRe: Generate Sequential Number without database Pin
T M Gray27-Jul-10 10:23
T M Gray27-Jul-10 10:23 
GeneralRe: Generate Sequential Number without database Pin
Maikeru200027-Jul-10 10:40
Maikeru200027-Jul-10 10:40 
GeneralRe: Generate Sequential Number without database Pin
T M Gray27-Jul-10 10:44
T M Gray27-Jul-10 10:44 
AnswerRe: Generate Sequential Number without database Pin
Adam R Harris28-Jul-10 8:52
Adam R Harris28-Jul-10 8:52 
Well if all you need is a simple way to do this you might try loading the last id from a flat text file or xml in Application_Start throw that into the application state and then in Application_End save it to the database. This way you dont have to worry about concurrency issues because the id is stored in memory and is only written back to the file when the application ends.

/* Global.asax */
void Application_Start(object sender, EventArgs e)
{
    int id;
    int.TryParse(System.IO.File.ReadAllText(Server.MapPath("~/nextid.txt")), out id);
    Application["ID"] = id;
}

void Application_End(object sender, EventArgs e)
{
    // Delete the old file
    System.IO.File.Delete(Server.MapPath("~/nextid.txt"));
    // Write out the new one
    System.IO.File.WriteAllLines(Server.MapPath("~/nextid.txt"), new string[] { Application["ID"].ToString() });
}

/* Some publicly accessible class */
public int GetNextID()
{
    // Increase the id
    Application["ID"] = Convert.ToInt32(Application["ID"]) + 1;
    return (int)Application["ID"];
}


Ofcourse you are going to want to add stuff like checking for the file before reading it and some error handling but im sure you get the point.
If at first you don't succeed ... post it on The Code Project and Pray.

Questiontips&tricks template Pin
farokhian27-Jul-10 5:39
farokhian27-Jul-10 5:39 
AnswerRe: tips&tricks template Pin
David Mujica27-Jul-10 6:02
David Mujica27-Jul-10 6:02 
Questionerror in dataRelation in asp.net [modified] Pin
Dhyanga27-Jul-10 3:08
Dhyanga27-Jul-10 3:08 
AnswerRe: error in dataRelation in asp.net Pin
Dhyanga27-Jul-10 7:19
Dhyanga27-Jul-10 7:19 
AnswerREPOST Pin
Not Active27-Jul-10 8:58
mentorNot Active27-Jul-10 8:58 
GeneralProblem not solved yet: error in using dataRelation in asp.net Pin
Dhyanga28-Jul-10 4:23
Dhyanga28-Jul-10 4:23 
QuestionJquery in asp.net Pin
Satish_S27-Jul-10 2:16
Satish_S27-Jul-10 2:16 
AnswerRe: Jquery in asp.net Pin
Yusuf27-Jul-10 4:12
Yusuf27-Jul-10 4:12 
GeneralRe: Jquery in asp.net Pin
Satish_S27-Jul-10 19:33
Satish_S27-Jul-10 19:33 
GeneralRe: Jquery in asp.net Pin
Not Active28-Jul-10 3:35
mentorNot Active28-Jul-10 3:35 
Questionsql backup through asp.net in script format Pin
gautamamit827-Jul-10 1:22
gautamamit827-Jul-10 1:22 
QuestionHow to Load another web site page content into my Web Page Application Pin
Sandilian26-Jul-10 20:37
Sandilian26-Jul-10 20:37 
AnswerRe: How to Load another web site page content into my Web Page Application Pin
Arun Jacob26-Jul-10 21:12
Arun Jacob26-Jul-10 21:12 
AnswerRe: How to Load another web site page content into my Web Page Application Pin
Sandesh M Patil27-Jul-10 6:46
Sandesh M Patil27-Jul-10 6:46 
Questionget back vs2005 project? Pin
Member 387988126-Jul-10 18:49
Member 387988126-Jul-10 18:49 
AnswerRe: get back vs2005 project? Pin
Arun Jacob26-Jul-10 19:12
Arun Jacob26-Jul-10 19:12 
Questionnested repeater Pin
Dhyanga26-Jul-10 5:48
Dhyanga26-Jul-10 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.