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 8930361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:52:40+00:00 2026-06-15T08:52:40+00:00

I’m really new to ASP.net and I am currently trying to create a registration

  • 0

I’m really new to ASP.net and I am currently trying to create a registration page on a site. I was successful in adding a user to the database but I decided to add another feature into the code to check what userID’s were available. For example, if a user deleted their account their userID would become available for use again. I’m trying to find the min value and the max value and add or subtract 1 depending on whether it is min or max. I can run the code I have written for this with no errors but the user is not added to the database. Can anyone help me figure out what I’m missing from my code to do this?

EDIT >>>>>
Code adds a user to database but it adds the new user at -1 instead. I don’t seem to be able to see where the issue is.

If (aDataReader2.Read() = False) Then
  aConnection1 = New OleDbConnection(aConnectionString)
  aConnection1.Open()
  aQuery = "Insert Into UserDetails "
  aQuery = aQuery & "Values ('" & userID & "','" & userFName & "','" & userLName & "','" & userEmail & "','" & userUsername & "','" & userPassword & "')"
  aCommand = New OleDbCommand(aQuery, aConnection1)
  aCommand.ExecuteNonQuery()
  aConnection1.Close()
ElseIf (min = 1) Then
  aConnection2 = New OleDbConnection(aConnectionString)
  aConnection2.Open()
  aCommand = New OleDbCommand(aQuery3, aConnection2)
  aDataReader2 = aCommand.ExecuteReader()
  userID = max + 1
  aQuery = "Insert Into UserDetails "
  aQuery = aQuery & "Values ('" & userID & "','" & userFName & "','" & userLName & "','" & userEmail & "','" & userUsername & "','" & userPassword & "')"
  aCommand = New OleDbCommand(aQuery, aConnection2)
  aCommand.ExecuteNonQuery()
  aConnection2.Close()
Else
  aConnection3 = New OleDbConnection(aConnectionString)
  aConnection3.Open()
  aCommand = New OleDbCommand(aQuery2, aConnection3)
  aDataReader2 = aCommand.ExecuteReader
  userID = min - 1
  aQuery = "Insert Into UserDetails "
  aQuery = aQuery & "Values ('" & userID & "','" & userFName & "','" & userLName & "','" & userEmail & "','" & userUsername & "','" & userPassword & "')"
  aCommand = New OleDbCommand(aQuery, aConnection3)
  aCommand.ExecuteNonQuery()
  aConnection3.Close()
  lblResults.Text = "User Account successfully created"
  btnCreateUser.Enabled = False
End If

Here’s the code I used to get the max and min values from the database. I’m getting a value of 0 for both of them – when min should be 1 and max should be 5

 Dim minID As Integer
 Dim maxID As Integer
 aQuery2 = "Select Min(UserID) AS '" & [minID] & "' From UserDetails"
 aQuery3 = "Select Max(UserID) AS ' " & [maxID] & "' From UserDetails"
  • 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-15T08:52:41+00:00Added an answer on June 15, 2026 at 8:52 am

    It’s hard to say what
    t the problem is exactly, since we see only a part of it. Where do min and max come from?

    I cannot give you a solution, however, I suggest you to structure your code better. You have a lot (!) of redundant code. This makes the code difficult to read, to understand, to change and to test.

    Put the user data into a class. This makes it easier to handle than a lot of individual variables.

    Public Class User
        Public Property ID As Integer
        Public Property FirstName As String
        Public Property LastName As String
        Public Property EMail As String
        Public Property Username As String
        Public Property Password As String
    End Class
    

    Extract redundant code into subroutines

    Private Sub CreateUser(ByVal u As User)
        Const InsertQuery As String = _
            "INSERT INTO UserDetails VALUES ({0},'{1}','{2}','{3}','{4}','{5}')"
    
        Dim query As String = String.Format(InsertQuery, u.ID, u.FirstName, u.LastName, _
                                                         u.Email, u.Username, u.Password)
        Using conn As New OleDbConnection(aConnectionString)
            conn.Open()
            Dim cmd As New OleDbCommand(query, conn)
            cmd.ExecuteNonQuery()
        End Using
    End Sub
    

    The code then becomes something like this

    If Not aDataReader2.Read() Then
        CreateUser(user)
    ElseIf min = 1 Then
        ...
        user.userID = max + 1
        CreateUser(user)
    Else
        ...
        user.userID = min - 1
        CreateUser(user)
        lblResults.Text = "User Account successfully created"
        btnCreateUser.Enabled = False
    End If
    

    This looks much nicer now.

    (My code is not tested, it’s just to give you an idea.)


    UPDATE

    You cannot read the min and max values like this. Try something like this

    Dim min, max As Integer
    
    Using conn As New OleDbConnection(aConnectionString)
        Dim cmd As OleDbCommand = _
            New OleDbCommand("SELECT MIN(UserID), MAX(UserID) FROM UserDetails", conn)
        conn.Open()
        Using reader As OleDbDataReader = cmd.ExecuteReader()
            reader.Read()
            If reader.IsDBNull(0) Then
                ' The table is empty
                min = 1
                max = 1
            Else
                min = reader.GetInt32(0)
                max = reader.GetInt32(1)
            End If
        End Using
    End Using
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to create an if statement in PHP that prevents a single post
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am trying to understand how to use SyndicationItem to display feed which is
I am currently running into a problem where an element is coming back from
I have a French site that I want to parse, but am running into

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.