Home > DeveloperSection > Forums > how achieve generative one have regularity id
Kenny Tangnde

Total Post:68

Points:476
Posted on    September-12-2011 4:34 AM

 C# C# 
Ratings:


 5 Reply(s)
 1641  View(s)
Rate this:

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.



Awadhendra Tiwari

Total Post:126

Points:882
Posted on    September-12-2011 5:30 AM

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.


Modified On Sep-12-2011 05:31:52 AM

Kenny Tangnde

Total Post:68

Points:476
Posted on    September-12-2011 8:26 AM

hi Awadhendra Tiwari ,

Perhaps this  not what I want

thanks.


Alex R
Alex R

Total Post:40

Points:280
Posted on    September-12-2011 10:01 AM

Hi Aken,

Could you please explain you question in a better way.

Thanks.


Kenny Tangnde

Total Post:68

Points:476
Posted on    September-14-2011 6:35 AM

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.

 


Kenny Tangnde

Total Post:68

Points:476
Posted on    September-14-2011 6:45 AM

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 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.


Don't want to miss updates? Please click the below button!

Follow MindStick