Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Dear All,

Can any body have a code how to create a alpha numeric code(eg. E000001).in the c# backend as sql2005.

Thanks in advance

Asgar Ali Baig
Posted
Updated 11-Dec-10 19:19pm
v3

Thank you for your question. You can follow bellow code.

C#
protected string GenerateCode(int NoOfCode)//NoOfCode is for No. of Pins
  {
      string pinnofinal="";
      int d1 = 0;
      int d2 = 0;
      int d3 = 0;
      int d4 = 0;
      int d5 = 0;
      int d6 = 0;
      int d7 = 0;
      int d8 = 0;
      for (int i = 0; i < NoOfCode; i++)
      {
          d1 = DateTime.Now.Millisecond + i;
          d2 = DateTime.Now.Second + i + 25;
          d3 = DateTime.Now.Second + i + 112;
          d4 = DateTime.Now.Second + i + 199;
          d5 = DateTime.Now.Second + i + 161;
          d6 = DateTime.Now.Second + i + 12;
          d7 = DateTime.Now.Second + i + 15;
          d8 = DateTime.Now.Millisecond + i;
          Random newno = new Random();
          string ranno = newno.Next(1111, 9999).ToString("x");
          string newpinno = ranno + d8.ToString("x") + d1.ToString("x") + d2.ToString("x") + d3.ToString("x") + d4.ToString("x") + d5.ToString("x") + d6.ToString("x") + d7.ToString("x");
          pinnofinal = newpinno.Substring(0, 14).ToUpper();
      }
      return pinnofinal;
  }



Thanks,
Mamun
 
Share this answer
 
v2
Comments
Richard MacCutchan 12-Dec-10 3:47am    
Why convert values to strings just so you can parse them back to integers?
Abdul Quader Mamun 12-Dec-10 23:40pm    
Make sense.
Abdul Quader Mamun 12-Dec-10 23:41pm    
Try with the code.
Another way.

C#
protected String GenerateCode(int LastNoOfCode)
 {
     String strAlphaNum = String.Empty;
     String strPrefix = "E";
             LastNoOfCode++;
     strAlphaNum = strPrefix + LastNoOfCode.ToString("000000");

     return strAlphaNum; 

 }


Thanks
 
Share this answer
 
v4

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