Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I want to generate sequence number in C# window application I have got one link in Google which is this[^], but I don't want like this way. I want that on click to add button an order sequence number should generate and stored in SQL Database and on base of order number i can view in "Data Grid View"

Thank in Advance :rose::rose:
Posted
Updated 11-Oct-10 0:29am
v5
Comments
Hiren solanki 7-Oct-10 5:03am    
Removed longish URL with 'THIS'.

If you want a reliable sequence numbering, you have to create it in the database, not in the app - think about multiple users at the same time ...
 
Share this answer
 
Comments
Dalek Dave 11-Oct-10 4:14am    
That's what he is asking for.
aayu 11-Oct-10 6:56am    
@Dalek he not she please don't change my gender

@ Thomas i am asking that only. and i want on the click Add button it should generate sequence number in sql
You can use a text file to generate and store the number.
C#
using System.IO;

private int GenerateSequenceNumber()
{
    string file2 = "test.txt";
    FileInfo fiRead = new FileInfo(file2);
    string input = string.Empty;
    int num = 1;
    if (fiRead.Exists)
    {
        input = File.ReadAllText(file2);
    }
    if (input != string.Empty)
    {
        num = Convert.ToInt32(input);
    }
    File.WriteAllText(file2, (num + 1).ToString());            
    return num;
}
 
Share this answer
 
v3
Comments
Richard MacCutchan 7-Oct-10 5:05am    
If you must post code then please put it inside <pre></pre> tags so it is readable. Read the posting guidelines for more information.
CPallini 8-Oct-10 15:41pm    
Why should he use a text file, having a database at his disposal?
shakil0304003 9-Oct-10 3:03am    
@Richard thanks
@CPallini he can use any thing he want, but i said about text file because it takes less time to me.
aayu 11-Oct-10 4:10am    
@Shakil Thanks for the reply
you have told that this sequence number will be stored in txt file but i want that it should be stored in sql data base can you please help me in that
aayu 11-Oct-10 5:59am    
@Shakil this code is giving me error which is
Unable to copy file "obj\Debug\.exe" to "bin\Debug\.exe". The process cannot access the file 'bin\Debug\.exe' because it is being used by another process.

i have comment the code then project is working properly please help me in this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900