---
title: "how achieve  generative one  have regularity id"  
description: "how achieve  generative one  have regularity id"  
author: "Kenny Tangnde"  
published: 2011-09-12  
updated: 2011-09-14  
canonical: https://www.mindstick.com/forum/307/how-achieve-generative-one-have-regularity-id  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# how achieve  generative one  have regularity id

hi all,

how achieve [generative](https://www.mindstick.com/blog/305715/it-leaders-see-generative-ai-as-a-game-changer-how) one have regularity id.

my code mind is below:

private void btnNewTranNum_Click(object sender, EventArgs e)\
{\
string constring = @"server=PC-aken\MYSQL;initial catalog=MySql; [integrated security](https://www.mindstick.com/forum/159040/what-is-the-difference-between-integrated-security-true-and-integrated-security-sspi)=SSPI; ";\
[SqlCommand](https://www.mindstick.com/forum/91/difference-between-sqlcommand-and-sqlcommandbuilder) cmd = new SqlCommand();\
cmd.CommandText = "SELECT *FROM TransportNum";\
[SqlConnection](https://www.mindstick.com/forum/1209/sqlconnection-sqlcommand-sqldatareader-idisposable) sqlcon = new SqlConnection(constring);\
cmd.Connection = sqlcon;\
sqlcon.Open();\
int k = Convert.ToInt32(cmd.ExecuteScalar());\
cmd.CommandText = "UPDATE TransportNum SET TransportNum=TransportNum+1";\
cmd.ExecuteNonQuery();\
\
\
[DateTime](https://www.mindstick.com/forum/12949/how-to-validate-if-a-datetime-field-is-not-null-empty) d = DateTime.Now;\
string todaydate = d.ToString("yyyymmdd");\
txtNum.Text = todaydate.ToString() + k.ToString();//txtNum.Text=2011091222

//although can achieve me desire,but this [Algorithm](https://www.mindstick.com/blog/119/implementing-cryptography-in-c-sharp-dot-net-by-using-sha1-algorithm) is not good ,all have better algorithm?

/*

[current date](https://www.mindstick.com/forum/323/find-the-day-name-and-month-name-from-current-date)(20110912) and [database](https://www.mindstick.com/articles/12226/use-of-database-in-sencha-extjs-and-insert-record-from-user-form-using-ajax) record number(22)\

as result is:2011091222

*/

\
}

thanks in advance.

## Replies

### Reply by Kenny Tangnde

Perhaps my problem is not detailed enough,I re-modify the code.

such as:

private void btnNewTransportID_Click(object sender, EventArgs e)\
{\
string constring = @"server=PC-aken\MYSQL;initial catalog=MySql; [integrated](https://www.mindstick.com/forum/33532/handler-pagehandlerfactory-integrated-has-a-bad-module-managedpipelinehandler-in-its-module-list) [security](https://www.mindstick.com/articles/43813/new-security-technologies)=SSPI; ";\
SqlCommand cmd = new SqlCommand();\
cmd.CommandText = "SELECT *FROM Reocrd _Number";\
SqlConnection sqlcon = new SqlConnection(constring);\
cmd.Connection = sqlcon;\
sqlcon.Open();

\
int k = Convert.ToInt32(cmd.ExecuteScalar());//k=22\
cmd.CommandText = "UPDATE Reocrd _Number SET RecordNum=RecordNum+1";\
cmd.ExecuteNonQuery();\
\
\
DateTime d = DateTime.Now;//get current date\
string todaydate = d.ToString("yyyymmdd");//format as:yyyymmdd\
txtID.Text = todaydate.ToString() + k.ToString();

}

//final: txtID.Text=2011091422.

### Reply by Kenny Tangnde

Hi Haider M Rizv,

generative id from at current date and record number.\
such as :

current date:9/14/2011

database table name is "Reocrd _Number" record value:22.

final compose generative id this:2011091422.\

### Reply by Anonymous User

Hi Aken,

Could you please explain you question in a better way.

Thanks.

### Reply by Kenny Tangnde

hi Awadhendra Tiwari ,

Perhaps this not what I want

thanks.

### Reply by Anonymous User

Hi aken H

I am facing some problem while understanding your query and question. Could you please explain it in more detail.

Here In your code which you mention, I think you would like to generate autamtic id number with complex datetime format.

If it is so then you can implement it at database level that is using procedure as well as using c#.

Here I mention link of procedure level as well as c# both.

http://www.mindstick.com/Blog/133/Auto%20increment%20id%20by%20using%20stored%20procedure

Above link show you that how to achive task of automatic incremented id at procedure level.

http://www.mindstick.com/Forum/173/Auto%20Increment%20ID

Following link is a descussion in which autoamtic id is generted using c#.

Maybe these link are helpful for you.

Thanks.


---

Original Source: https://www.mindstick.com/forum/307/how-achieve-generative-one-have-regularity-id

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
