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. General Programming
  3. Visual Basic
  4. Automatic generation of numbers

Automatic generation of numbers

Scheduled Pinned Locked Moved Visual Basic
csharphelp
4 Posts 4 Posters 0 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.
  • A Offline
    A Offline
    Arun Hegde
    wrote on last edited by
    #1

    Dear Sir, i amworking on vb.net i have a textbox field in the form called CardId now what i want is to generate numbers automatically and in a sequence. Suppose, when i click on the ADD RECORD button to add a new record, the cardid should be automatically generated as 1. if the record is saved ,then the next time when i am trying to add another record the cardid should be 2. but if the first record having cardid 1 is not saved then the next time i am adding a record the card id should be 1. can u pl help me through code. Arun

    L R S 3 Replies Last reply
    0
    • A Arun Hegde

      Dear Sir, i amworking on vb.net i have a textbox field in the form called CardId now what i want is to generate numbers automatically and in a sequence. Suppose, when i click on the ADD RECORD button to add a new record, the cardid should be automatically generated as 1. if the record is saved ,then the next time when i am trying to add another record the cardid should be 2. but if the first record having cardid 1 is not saved then the next time i am adding a record the card id should be 1. can u pl help me through code. Arun

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      dear arun, You can refer the code below. Function GenerateCode() As String Dim MyCommand As SqlClient.SqlDataAdapter Dim Dsg As New Customer Dim LastRec As Integer Try MyCommand = New SqlClient.SqlDataAdapter("select * from Cusdetail order by 1 asc", Myconnection) MyCommand.Fill(Dsg, "Cusdetail") LastRec = Dsg.CusDetail.Count() If LastRec > 0 Then LastRec = LastRec - 1 TxtCusCode.Text = Ds.CusDetail(LastRec).CusCode + 1 Else TxtCusCode.Text = "100001" 'Code for first Customer End If Catch ex As Exception Label11.Text = ex.Message() End Try Myconnection.Close() End Function Thankx Murtuza Patel.

      1 Reply Last reply
      0
      • A Arun Hegde

        Dear Sir, i amworking on vb.net i have a textbox field in the form called CardId now what i want is to generate numbers automatically and in a sequence. Suppose, when i click on the ADD RECORD button to add a new record, the cardid should be automatically generated as 1. if the record is saved ,then the next time when i am trying to add another record the cardid should be 2. but if the first record having cardid 1 is not saved then the next time i am adding a record the card id should be 1. can u pl help me through code. Arun

        R Offline
        R Offline
        rikky_222
        wrote on last edited by
        #3

        this is easy...u can get the cardid field from the database into a dataset...and check for the largest number...and then add 1 to it and set it as ur generated number in the text box... subhrajyoti

        1 Reply Last reply
        0
        • A Arun Hegde

          Dear Sir, i amworking on vb.net i have a textbox field in the form called CardId now what i want is to generate numbers automatically and in a sequence. Suppose, when i click on the ADD RECORD button to add a new record, the cardid should be automatically generated as 1. if the record is saved ,then the next time when i am trying to add another record the cardid should be 2. but if the first record having cardid 1 is not saved then the next time i am adding a record the card id should be 1. can u pl help me through code. Arun

          S Offline
          S Offline
          Solid Snake
          wrote on last edited by
          #4

          is it not easier to use Access for that sort of things?

          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