Sponsored By
MindStick SurveyManager
Advertise with Us
Advertisement
Advertise with Us
Follow Us
Follow _MindStick_ on Twitter View MindStick Software's LinkedIn profile View MindStick Software's Facebook profile
Mindstick
Article Article  Forum Forum  Blog Blog  Quiz Quiz  Beginner Beginner  Careers Careers  Contact Contact  Login Login  
Home | Product | Services | About Us | Interview | DeveloperSection | Submit an Article | Submit Blog
Report Abuse Form
Reason:    
   

Home >> .Net >> C# >> how achieve generative one have regularity id
Author Post

aken H


Total Post: 66
Member Since: 9/6/2011
Points: 419
how achieve generative one have regularity id
Posted On: 9/12/2011 4:34:42 AM

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.

Author Post

Awadhendra Tiwari


Total Post: 126
Member Since: 1/19/2011
Points: 893
Re: how achieve generative one have regularity id
Posted On: 9/12/2011 5:30:39 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: 9/12/2011 5:31:52 AM
Author Post

aken H


Total Post: 66
Member Since: 9/6/2011
Points: 419
Re: how achieve generative one have regularity id
Posted On: 9/12/2011 8:26:13 AM

hi Awadhendra Tiwari ,

Perhaps this  not what I want

thanks.

Author Post

Haider M Rizvi


Total Post: 40
Member Since: 6/6/2010
Points: 291
Re: how achieve generative one have regularity id
Posted On: 9/12/2011 10:01:18 AM

Hi Aken,

Could you please explain you question in a better way.

Thanks.

Author Post

aken H


Total Post: 66
Member Since: 9/6/2011
Points: 419
Re: how achieve generative one have regularity id
Posted On: 9/14/2011 6:35:49 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.

 

Author Post

aken H


Total Post: 66
Member Since: 9/6/2011
Points: 419
Re: how achieve generative one have regularity id
Posted On: 9/14/2011 6:45:30 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.

Report Abuse Form
Reason:    
 
Total Online Users: 4620
Advertisement
MindStick DataConverter
Advertise with Us
  
Copyright © 2009 - 2013MindStick. All Rights Reserved.