HOW ACHIEVE GENERATIVE ONE HAVE REGULARITY ID

Kenny Tangnde

Total Post:68

Points:476
Posted by  Kenny Tangnde
C# 
C#
 1996  View(s)
Ratings:
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.

  1. Awadhendra Tiwari

    Post:126

    Points:882
    Re: how achieve generative one have regularity id

    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
  1. Kenny Tangnde

    Post:68

    Points:476
    Re: how achieve generative one have regularity id

    hi Awadhendra Tiwari ,

    Perhaps this  not what I want

    thanks.

  1. Alex R

    Post:40

    Points:280
    Re: how achieve generative one have regularity id

    Hi Aken,

    Could you please explain you question in a better way.

    Thanks.

  1. Kenny Tangnde

    Post:68

    Points:476
    Re: how achieve generative one have regularity id

    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.

     

  1. Kenny Tangnde

    Post:68

    Points:476
    Re: how achieve generative one have regularity id

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!