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

  • Home
  • SEARCH
  • 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 8194043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:41:14+00:00 2026-06-07T04:41:14+00:00

I have the following UPDATE command (written in VB) in my code. Dim currentUser

  • 0

I have the following UPDATE command (written in VB) in my code.

Dim currentUser As String = User.Identity.Name

    Dim myConnectionString As String = ConfigurationManager.ConnectionStrings("DBConnection").ConnectionString
    Dim myCommand As New SqlCommand("UPDATE tblProfile SET Title= @Title, FirstName= @FirstName, LastName= @LastName, MiddleName= @MiddleName, HomePhoneNumber= @HomePhoneNumber, MobilePhoneNumber= @MobilePhoneNumber, Address= @Address, StreetName= @StreetName, StreetType= @StreetType, Suburb= @Suburb, PostCode= @PostCode, State= @State WHERE UserName = '" & currentUser & "'", New SqlConnection(myConnectionString))
    myCommand.Connection.Open()
    myCommand.Parameters.AddWithValue("@Title", Title.SelectedItem.Text)
    myCommand.Parameters.AddWithValue("@FirstName", FirstName.Text)
    myCommand.Parameters.AddWithValue("@LastName", LastName.Text)
    If MiddleNames.Text = String.Empty Then
        myCommand.Parameters.AddWithValue("@MiddleName", DBNull.Value)
    Else
        myCommand.Parameters.AddWithValue("@MiddleName", MiddleNames.Text)
    End If
    If HomePhoneNumber.Text = String.Empty Then
        myCommand.Parameters.AddWithValue("@HomePhoneNumber", DBNull.Value)
    Else
        myCommand.Parameters.AddWithValue("@HomePhoneNumber", HomePhoneNumber.Text)
    End If
    If MobilePhoneNumber.Text = String.Empty Then
        myCommand.Parameters.AddWithValue("@MobilePhoneNumber", DBNull.Value)
    Else
        myCommand.Parameters.AddWithValue("@MobilePhoneNumber", MobilePhoneNumber.Text)
    End If
    myCommand.Parameters.AddWithValue("@Address", AddressNumber.Text)
    myCommand.Parameters.AddWithValue("@StreetName", StreetName.Text)
    myCommand.Parameters.AddWithValue("@StreetType", StreetType.SelectedItem.Text)
    myCommand.Parameters.AddWithValue("@Suburb", Suburb.Text)
    myCommand.Parameters.AddWithValue("@PostCode", Postcode.Text)
    myCommand.Parameters.AddWithValue("@State", State.SelectedItem.Text)

    myCommand.ExecuteNonQuery()
    myCommand.Connection.Close()

    Dim myCommandPref As New SqlCommand("UPDATE tblPreferences SET Classical = @Classical, Comedy = @Comedy, Concerts = @Concerts, Dance = @Dance, DiningOut = @DiningOut, Exhibitions = @Exhibitions, Family = @Family, Festivals = @Festivals, Lifestyle = @Lifestyle, Musicals = @Musicals, Opera = @Opera, Rock = @Rock, Sports = @Sports, Theatre = @Theatre WHERE UserName = '" & currentUser & "'", New SqlConnection(myConnectionString))

    myCommandPref.Connection.Open()

    Dim boolClassical As Boolean = Preferences.Items(0).Selected
    myCommandPref.Parameters.AddWithValue("@Classical", boolClassical.ToString)

    Dim boolComedy As Boolean = Preferences1.Items(0).Selected
    myCommandPref.Parameters.AddWithValue("@Comedy", boolComedy.ToString)

    Dim boolConcerts As Boolean = Preferences.Items(1).Selected
    myCommandPref.Parameters.AddWithValue("@Concerts", boolConcerts.ToString)

    Dim boolDance As Boolean = Preferences1.Items(1).Selected
    myCommandPref.Parameters.AddWithValue("@Dance", boolDance.ToString)

    Dim boolDiningOut As Boolean = Preferences.Items(2).Selected
    myCommandPref.Parameters.AddWithValue("@DiningOut", boolDiningOut.ToString)

    Dim boolExhibitions As Boolean = Preferences1.Items(2).Selected
    myCommandPref.Parameters.AddWithValue("@Exhibitions", boolExhibitions.ToString)

    Dim boolFamily As Boolean = Preferences.Items(3).Selected
    myCommandPref.Parameters.AddWithValue("@Family", boolFamily.ToString)

    Dim boolFestivals As Boolean = Preferences1.Items(3).Selected
    myCommandPref.Parameters.AddWithValue("@Festivals", boolFestivals.ToString)

    Dim boolLifestyle As Boolean = Preferences.Items(4).Selected
    myCommandPref.Parameters.AddWithValue("@Lifestyle", boolLifestyle.ToString)

    Dim boolMusicals As Boolean = Preferences1.Items(4).Selected
    myCommandPref.Parameters.AddWithValue("@Musicals", boolMusicals.ToString)

    Dim boolOpera As Boolean = Preferences.Items(5).Selected
    myCommandPref.Parameters.AddWithValue("@Opera", boolOpera.ToString)

    Dim boolRock As Boolean = Preferences1.Items(5).Selected
    myCommandPref.Parameters.AddWithValue("@Rock", boolRock.ToString)

    Dim boolSports As Boolean = Preferences.Items(6).Selected
    myCommandPref.Parameters.AddWithValue("@Sports", boolSports.ToString)

    Dim boolTheatre As Boolean = Preferences1.Items(6).Selected
    myCommandPref.Parameters.AddWithValue("@Theatre", boolTheatre.ToString)

    myCommandPref.ExecuteNonQuery()
    myCommandPref.Connection.Close()

When the user presses the button which fires that code, my page simply refreshes, but does not update the information in the database. I have looked around, and some people were saying you needed to have the primary key as the ‘where’ statement, so I made ‘UserName’ the primary key in both tables.

Could someone please help me to fix this.

  • 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-07T04:41:18+00:00Added an answer on June 7, 2026 at 4:41 am

    I went back to my code after a few months today, and after a brief search through, found the problem… I needed to include ‘if not IsPostBack then…’ to my Page_Load. I was resetting my page each time the button was pressed, which reset the fields on my page, thus sending the same information back to my server – I was updating my server with the same information.

    For anyone with the same problem, this helped me:
    http://www.java-samples.com/showtutorial.php?tutorialid=1083

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

Sidebar

Related Questions

I quite often have rows of code like the following: UPDATE my_table SET name
I have the following code: UPDATE myTable SET Col1 = @Value However, I have
I have the following code: $SQL = UPDATE jobs SET read = '1' WHERE
I have written following method with three sql queries in order to update a
UPDATE ** STILL LOOKING FOR A CORRECT ANSWER ** I have the following code
I have tried the following MySQL update but it only sets the first field
For my test I have the following: test should update holder do holder =
I have been following the answer of this question: How to update existing object
I have the following SQL statement where i'm trying to update multiple rows matching
Currently I have to write the following to update an element already contained in

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.