hi all,
how achieve generative 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=SSPI; ";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "SELECT *FROM TransportNum";
SqlConnection 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 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 is not good ,all have better algorithm?
/*
current date(20110912) and database record number(22)
as result is:2011091222
*/
}
thanks in advance.
Kenny Tangnde
14-Sep-2011Perhaps 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 security=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.
Kenny Tangnde
14-Sep-2011Hi 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.
Anonymous User
12-Sep-2011Hi Aken,
Could you please explain you question in a better way.
Thanks.
Kenny Tangnde
12-Sep-2011hi Awadhendra Tiwari ,
Perhaps this not what I want
thanks.
Anonymous User
12-Sep-2011Hi 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.