Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:00:38+00:00 2026-06-13T07:00:38+00:00

Is there anyway I can generate a unique sequence number using c#.we are developing

  • 0

Is there anyway I can generate a unique sequence number using c#.we are developing a website where we assign a personal id to each user at the time of registration… I need to generate a 14 digit string.

For eg.

AA 01 201 210 22

AA 02 201 210 22

.

.

AA 99 201 210 22

then it should start from

AB 01 201 210 22

AB 02 201 210 22 and so on...

Last 8 digits are current date...

Thanks....



private string ConvertDecString(int value)
       {
            string CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string retVal = string.Empty;
            int remainder = 0;
            do
            {
                remainder = value % 26;
                retVal = CHARS.Substring(remainder, 1) + retVal;
                value = (value / 26) - 1;
            }
            while ((value + 1) > 0);
            return retVal;
        }


public string GetCurrentDate()
    {
        string todaydate = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString();
        return todaydate;
    }

    private Random _random = new Random();

    public int RadomNum()
    {
        return _random.Next(10, 99);
    }

private string GetActualDate()
    {
        string Year = System.DateTime.Now.Year.ToString();
        string ActualDate1 = Year + GetProperMonth() + GetProperDay();
        int n = Convert.ToInt32(ActualDate1);
        string ActualDate = String.Format("{0:000 000 00}", n);
        return ActualDate;
    }

    private string GetProperMonth()
    {
        string Month = System.DateTime.Now.Month.ToString();
        string MonthNo = "";

        if (Month == "1")
        {
            MonthNo = "01";
        }
        else if (Month == "2")
        {
            MonthNo = "02";
        }
        else if (Month == "3")
        {
            MonthNo = "03";
        }
        else if (Month == "4")
        {
            MonthNo = "04";
        }
        else if (Month == "5")
        {
            MonthNo = "05";
        }
        else if (Month == "6")
        {
            MonthNo = "06";
        }
        else if (Month == "7")
        {
            MonthNo = "07";
        }
        else if (Month == "8")
        {
            MonthNo = "08";
        }
        else if (Month == "9")
        {
            MonthNo = "09";
        }
        else
        {
            MonthNo = Month;
        }
        return MonthNo;
    }


    private string GetProperDay()
    {
        string Day = System.DateTime.Now.Day.ToString();
        string DayNo = "";

        if (Day == "1")
        {
            DayNo = "01";
        }
        else if (Day == "2")
        {
            DayNo = "02";
        }
        else if (Day == "3")
        {
            DayNo = "03";
        }
        else if (Day == "4")
        {
            DayNo = "04";
        }
        else if (Day == "5")
        {
            DayNo = "05";
        }
        else if (Day == "6")
        {
            DayNo = "06";
        }
        else if (Day == "7")
        {
            DayNo = "07";
        }
        else if (Day == "8")
        {
            DayNo = "08";
        }
        else if (Day == "9")
        {
            DayNo = "09";
        }
        else
        {
            DayNo = Day;
        }
        return DayNo;
    }

    public string GeneratePatientNumber(string Alpha)
        {
            return ConvertDecString(Convert.ToInt16(Alpha)) + " " + RadomNum() + " " + GetActualDate();
        }

GeneratePatientNumber(string Alpha) - this method generates 12 digit personal id...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:00:39+00:00Added an answer on June 13, 2026 at 7:00 am
    public string GetPersonalId (int n)
    {
        char letter1 = (char)('A' + ((n / 10 / 26 / 26) % 26));
        char letter2 = (char)('A' + ((n / 10 / 26) % 26));
        char digit1 = (char)('0' + ((n / 10) % 10));
        char digit2 = (char)('0' + ((n) % 10));
    
        string dateString = string.Format("{0:yyyyMMdd}", DateTime.Today)
            .Insert(6, " ")
            .Insert(3, " ");
    
        return string.Format("{0}{1} {2}{3} {4}",
            letter1, letter2, digit1, digit2, dateString);
    }
    
    public GetNextSequenceForToday()
    {
        SqlCommand query = new SqlCommand()
        query.CommandText =
           "SELECT COUNT(*) FROM [Users] " +
           "WHERE [Date] >= @today AND [Date] < @tomorrow";
        query.Parameters.Add("@today", DateTime.Today);
        query.Parameters.Add("@tomorrow", DateTime.Today.AddDays(1));
    
        int count = Convert.ToInt32(query.ExecuteScalar());
    
        return count + 1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway I can detect via jQuery if a select form element is
Is there anyway I can save a List variable to the Androids phone internal
Is there anyway I can execute stored procedure via EXEC (so not specifying CommandType.StoredProcedure
Is there anyway I can create nodes out of a string? I've searched the
Is there anyway I can clean up if($class == 2 AND $posts >=1){$showpost =1;}
Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
Is there anyway we can take input from command line in Objective-C, the way
Is there anyway I can look at the size of a file the application
Is there anyway i can fool the Jquery .load Same origin policy? The closest
Is there anyway I can use to destroy my deployed application at specific date?.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.