ASP.NET - how to auto generate this 00001 number asp.net with c#

Asked By siva on 05-Apr-11 02:12 AM
auto generate 1 to continues 

 SqlConnection con1 = new SqlConnection("Data Source=CPU253;Initial Catalog=ncrcar;Integrated Security=True");
      con1.Open();
      
      SqlCommand cmd2 = new SqlCommand("Select Max(ncrno) as ncrno from ncrcar", con1);
      

      cmd2.CommandType = CommandType.Text;
      SqlDataReader r = cmd2.ExecuteReader();
     
      r.Read();

      if (r["ncrno"].ToString() != "")
      {
        
        temp = int.Parse(r["ncrno"].ToString()) + 1;
      }
      else
      {
        temp = 1;

      }
     

     
      TextBox27.Text = temp.ToString();
      r.Close();
      con1.Close();
    }
but prefix 00001 series wise store in database please help me
sweta * replied to siva on 05-Apr-11 02:16 AM
if temp is an integer then format it like
temp.ToString("00000");
sweta * replied to siva on 05-Apr-11 02:16 AM
if temp is an integer then format it like
temp.ToString("00000");
Nikhil Mahajan replied to siva on 05-Apr-11 03:17 AM
you dont have to do any major change in ur code just change

1. just make 2 columns one with int datatype and other with varchar datatype.
and while inserting insert the both column..(one with int datatype and one with varchar datatype)

2. select from column with int datatype....and put 0000 prefix and insert it into column with varchar datatype.....