Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. how to generate unique number

how to generate unique number

Scheduled Pinned Locked Moved ASP.NET
tutorialcsharpdatabasequestion
6 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    biswa47
    wrote on last edited by
    #1

    i have a gridview which is storing a record .i want to generate a unique no while saving one record. the format should be like (pscode(2place),year(4place)and num(4place)) example:--01-2007-0001 where ps_code is char(2), year come form date-which is of date and time datattype and the last 4 place are char(4), where ps_code and date are the field of my data base.i want retrive ps_code and year from my database to generate the unique number. can tell me how will i do it? i am devloping a web applcation where the backend is vb.net2005.

    I N J 3 Replies Last reply
    0
    • B biswa47

      i have a gridview which is storing a record .i want to generate a unique no while saving one record. the format should be like (pscode(2place),year(4place)and num(4place)) example:--01-2007-0001 where ps_code is char(2), year come form date-which is of date and time datattype and the last 4 place are char(4), where ps_code and date are the field of my data base.i want retrive ps_code and year from my database to generate the unique number. can tell me how will i do it? i am devloping a web applcation where the backend is vb.net2005.

      I Offline
      I Offline
      Imran Khan Pathan
      wrote on last edited by
      #2

      select Max last number of Unique code and increament it by 1 Best Regard Pathan

      ---------------------------------------------------

      N 1 Reply Last reply
      0
      • B biswa47

        i have a gridview which is storing a record .i want to generate a unique no while saving one record. the format should be like (pscode(2place),year(4place)and num(4place)) example:--01-2007-0001 where ps_code is char(2), year come form date-which is of date and time datattype and the last 4 place are char(4), where ps_code and date are the field of my data base.i want retrive ps_code and year from my database to generate the unique number. can tell me how will i do it? i am devloping a web applcation where the backend is vb.net2005.

        N Offline
        N Offline
        nandhububbly
        wrote on last edited by
        #3

        Hi u generate unique no thr sqlserver , there identity proper is there u changed as true then u can generate... steps 1.open ur table thr Sqlserver enterprise manages then open ur table below ur table that identity option is there Reg Nantha

        M 1 Reply Last reply
        0
        • I Imran Khan Pathan

          select Max last number of Unique code and increament it by 1 Best Regard Pathan

          ---------------------------------------------------

          N Offline
          N Offline
          nandhububbly
          wrote on last edited by
          #4

          Hi first u create one column for that no,then if u enable identity as true then below that they put increment as 1 by default , if u need increment by 2 or any value u can put , u ref that increment value to that column (ie new column for that no) , then that no's stored in that column u can ref that column u can easly fetch that no Reg Nanthakumar

          1 Reply Last reply
          0
          • N nandhububbly

            Hi u generate unique no thr sqlserver , there identity proper is there u changed as true then u can generate... steps 1.open ur table thr Sqlserver enterprise manages then open ur table below ur table that identity option is there Reg Nantha

            M Offline
            M Offline
            Malcolm Smart
            wrote on last edited by
            #5

            What is 'ur' table?

            "More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF

            "I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.

            1 Reply Last reply
            0
            • B biswa47

              i have a gridview which is storing a record .i want to generate a unique no while saving one record. the format should be like (pscode(2place),year(4place)and num(4place)) example:--01-2007-0001 where ps_code is char(2), year come form date-which is of date and time datattype and the last 4 place are char(4), where ps_code and date are the field of my data base.i want retrive ps_code and year from my database to generate the unique number. can tell me how will i do it? i am devloping a web applcation where the backend is vb.net2005.

              J Offline
              J Offline
              Justin Jones 0
              wrote on last edited by
              #6

              If I understand your problem you need a unique integer when saving your record. Why not just use an identity column in your table and return that through an output parameter in your save procedure? Another approach I've seen often is using GUID. You can generate that at the time your object is created and it (is supposed to) be unique. HTH

              J Make the logo bigger

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups