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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:25:10+00:00 2026-06-01T00:25:10+00:00

I have a button which when pressed, sets the user’s rights in the db.

  • 0

I have a button which when pressed, sets the user’s rights in the db. (If Administrator UserTypeID is set to ‘2’ and if Customer it is set to ‘1’). However when I run the below code, everything remains the same. I think it’s from the SQL statement but I;m not sure. Can anyone help please?

Protected Sub btnSetUser_Click(sender As Object, e As System.EventArgs) _
    Handles btnSetUser.Click

    Dim conn As New OleDbConnection( _
      "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\...\WebSite3\db.mdb;")

    Dim cmd As OleDbCommand = _
      New OleDbCommand("UPDATE [User] SET [UserTypeID] WHERE Username=?", conn)

    conn.Open()
    cmd.Parameters.AddWithValue("@Username", txtUser.Text)

    If ddUserType.SelectedItem.Text = "Administrator" Then
        cmd.Parameters.AddWithValue("@UserTypeID", "2")
        cmd.ExecuteNonQuery()
        lblSetUser.Text = txtUser.Text + "was set to Administrator."
    ElseIf ddUserType.SelectedItem.Text = "Customer" Then
        cmd.Parameters.AddWithValue("@UserTypeID", "1")
        cmd.ExecuteNonQuery()
        lblSetUser.Text = txtUser.Text + "was set to Customer."
    End If

    conn.Close()
End Sub

End Class

  • 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-01T00:25:12+00:00Added an answer on June 1, 2026 at 12:25 am

    If you add a parameter @Username your command should have such a parameter

    SELECT [UserTypeID] FROM [User] WHERE Username = @Username
    

    Also, you add an additional parameter later, which does not occur at all in your query! You call cmd.ExecuteNonQuery(), which works only for INSERT, UPDATE and DELETE queries.

    Your query should probably look like this

    UPDATE [User]
    SET UserTypeID = @UserTypeID
    WHERE Username = @Username
    

    Dim cmd As OleDbCommand = New OleDbCommand( _
      "UPDATE [User] SET UserTypeID = @UserTypeID WHERE Username = @Username", conn)
    
    Dim userType As String = ddUserType.SelectedItem.Text
    Dim userTypeId As Integer = If(userType = "Administrator", 2, 1)
    
    cmd.Parameters.AddWithValue("@UserTypeID", userTypeId)
    cmd.Parameters.AddWithValue("@Username", txtUser.Text)             
    conn.Open()
    cmd.ExecuteNonQuery()
    lblSetUser.Text = txtUser.Text + "was set to " & userType
    

    UPDATE (some clarifications)

    In "UDATE [User] SET UserTypeID = @UserTypeID WHERE Username = @Username"

  2. [User]              is the name of the table
  3. UserTypeID      is the name of the user type id column
  4. @UserTypeID    is the name of the user type id parameter (the new value)
  5. Username          is the name of the user name column
  6. @Username        is the name of the user name parameter
  7. You might have to change these names in order to match your actual situation.

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

Sidebar

Related Questions

I have a button which when pressed, should push the controls below it down
I have a button which I wanted to flash briefly to get the user's
I have a Clear button which sets the gridview datasource to null and binds
I have a login window with a Sign In button which is set as
I am using visual basic 6. I have a button created which when pressed
I have a button which when pressed makes calls that load information from a
I have a home button on my scene which when pressed goes to the
In my iPhone application I have an update button which when being pressed adds
I have a button on an activity which when pressed loops through a list
I have a form with a few buttons which execute code when pressed like

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.