Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9283523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T18:39:10+00:00 2026-06-18T18:39:10+00:00

I have a problem with my program, I need to INCREMENT the value of

  • 0

I have a problem with my program, I need to INCREMENT the value of a certain Label

 Dim p1num As Integer = 0
 M.Text = Format(Now, "MM")
 Y.Text = Format(Now, "yy")

txtPNumber.Text = Y.Text.ToString & M.Text.ToString & p1num.ToString("D4")

I use this to generate the Patient ID, where in the M is for Month and the Y is for Year + the p1num to create a 4 digit number…. so the output will be like this:

(Let use the current date and year)

13020001
13020002
13020003
13020004

and so on….

After this, I will use these codes to insert it to my DB in SQL SERVER :

Dim SQLcon As New SqlConnection
        Dim SQLdr As SqlDataReader
        Try
            SQLcon.ConnectionString = "Data Source=####;" & _
"Initial Catalog=####;Persist Security Info=True;User ID=####;Password="
            Dim SQLcmd As New SqlCommand("INSERT INTO dbo.Patients" & _
                                         "(pIDNo)" & _
                                         "VALUES(@pIDNo)", SQLcon)
            SQLcmd.Parameters.AddWithValue("@pIDNo", txtPNumber.Text)
 MsgBox("Patient Added!", MsgBoxStyle.Information)
            SQLdr = SQLcmd.ExecuteReader()
        Catch ex As Exception
            MessageBox.Show("Error Occured, Can't Add Patient!" & ex.Message)
        Finally
            SQLcon.Close()
        End Try
        Return ""

the problem now is that when I close the program the value that generates to my TextBox is start always in 13020001. I want to retain the value that recently added and then increment it to +1 so I plan to display the current ID that just added to my DB using these :

  Dim querystring As String = "SELECT MAX(pIDNo) FROM dbo.Patients"

            Using connection As New SqlConnection("Data Source=####;" & _
    "Initial Catalog=####;Persist Security Info=True;User ID=####;Password=")
                Dim command As New SqlCommand(querystring, connection)
                connection.Open()
                Dim reader As SqlDataReader = command.ExecuteReader
                While reader.Read
                    txtCurrentID.Text = reader.GetString(0)
                End While
                reader.Close()

I manage to display the current ID but the problem now is I can’t increment it by 1.

Other problem : I try to copy the displayed value and just add it by one but another problem came up, the month and year doesn’t change. If I reached the month ‘MARCH’ the value that generates is still

1302 + pnum1.text(“D4”) that supposed to be 1303 + pnum1.text(“D4”)

1302 is for FEBRUARY
1303 is for MARCH

could anyone have a solution with my problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T18:39:11+00:00Added an answer on June 18, 2026 at 6:39 pm
     While reader.Read       //you don't need that for aggregate functions. 
         txtCurrentID.Text = command.ExecuteScaler() //something like that... is enough 
         int p1num=integer.parse(txt.CurrentID.text.substring(4,4)) +1
     //  End While
     ...
    
    txtPNumber.Text = Y.Text.ToString & M.Text.ToString & p1num.ToString("D4")
    

    if you just want the date: then use Date.Today

           pNumber.Text = Today.Date.Month.ToString + " " + Today.Date.Year.ToString
    

    IntelliSense is your first book so must use it. 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem with my program,I need to write to file how much games
I have an WPF application. The problem: need program(daemon, service) that send signals by
I have a problem with writting this program I need to read a csv
i have a problem,one of my client need a program that will connect to
I have a problem with an (I guess) simple Java program. I need to
I have a problem in which I need to be prepared to explore a
I have a problem with my first JMonkeyEngine program. I am getting this: java.lang.UnsupportedOperationException:
I Have this class to demonstrate my problem: class Program { static List<FileInfo> _foundFiles;
I have a problem. I wrote a program that converts some large amount of
i have the following problem. The 1st step is to implement a program, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.