How to make a Random Number with Unique Code

  1. protected void Page_Load(object sender, EventArgs e)  
  2. {  
  3.     autogenerated(); //its a call for auto no. function  
  4. }  
  5. void autogenerated()   
  6. {  
  7.     string connection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;  
  8.     SqlConnection con = new SqlConnection(connection);  
  9.     str = "select max(abid) as abid from abstracted";  
  10.     com = new SqlCommand(str, con);  
  11.     con.Open();  
  12.     count = Convert.ToInt16(com.ExecuteScalar()) + 1;  
  13.     Label1auto.Text = "AB00" + count.ToString();  
  14.     con.Close();  
  15. }  
Html code
  1. <asp:Label ID="Label1auto" runat="server"  
  2. Visible="true"></asp:Label>  
Data table scripts
  1. CREATE TABLE [dbo].[abstracted](  
  2. [id] [int] IDENTITY(1,1) NOT NULL,  
  3. [abid] [nvarchar](255) NULL,  
  4. [abno] [nvarchar](255) NULL,  
  5. [abtype] [nvarchar](255) NULL,  
  6. [category] [nvarchar](255) NULL,  
  7. [name] [nvarchar](255) NULL,  
  8. [design] [nvarchar](255) NULL  
  9. ON [PRIMARY]  
Web config
  1. <connectionStrings>  
  2. <!--<add name="ConnectionString" connectionString=" Data Source=.\SQLEXPRESS;database=dmcg_admin;Integrated Security=True" providerName="System.Data.SqlClient" />-->  
  3. </connectionStrings>  
Output

Auto no -AB001