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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:15:59+00:00 2026-06-18T02:15:59+00:00

I am trying to update some records after a new record was inserted where

  • 0

I am trying to update some records after a new record was inserted where it was not updating and I’m not getting any error.

Here is my code:

    If txtSearch.Text <> txtUserID.Text Then
        Try
            Dim connectionString As String = "Data Source=.\SqlExpress;Initial Catalog=Subscription;Integrated Security=True"
            Using cn As New SqlConnection(connectionString)
                cn.Open()
                cmd.CommandText = "INSERT INTO Customers (UserID, RegisteredDate, ExpiryDate, FirstName, LastName, Address, State, City, Phone, Mobile, Email) VALUES(@UserID, @RegisteredDate, @ExpiryDate, @FirstName, @LastName, @Address, @State, @City, @Phone, @Mobile, @Email)"

                Dim param1 As New SqlParameter()
                param1.ParameterName = "@UserID"
                param1.Value = txtUserID.Text.Trim()
                cmd.Parameters.Add(param1)

                Dim param2 As New SqlParameter()
                param2.ParameterName = "@RegisteredDate"
                param2.Value = RegisteredDate.Value
                cmd.Parameters.Add(param2)

                Dim param3 As New SqlParameter()
                param3.ParameterName = "@ExpiryDate"
                param3.Value = ExpiryDate.Value
                cmd.Parameters.Add(param3)

                Dim param4 As New SqlParameter()
                param4.ParameterName = "@FirstName"
                param4.Value = txtFirstName.Text.Trim()
                cmd.Parameters.Add(param4)

                Dim param5 As New SqlParameter()
                param5.ParameterName = "@LastName"
                param5.Value = txtLastName.Text.Trim()
                cmd.Parameters.Add(param5)


                Dim param6 As New SqlParameter()
                param6.ParameterName = "@Address"
                param6.Value = txtAddress.Text.Trim()
                cmd.Parameters.Add(param6)

                Dim param7 As New SqlParameter()
                param7.ParameterName = "@State"
                param7.Value = cboState.SelectedItem.ToString
                cmd.Parameters.Add(param7)

                Dim param8 As New SqlParameter()
                param8.ParameterName = "@City"
                param8.Value = cboCity.SelectedItem.ToString
                cmd.Parameters.Add(param8)

                Dim param9 As New SqlParameter()
                param9.ParameterName = "@Phone"
                param9.Value = txtPhone.Text.Trim()
                cmd.Parameters.Add(param9)

                Dim param10 As New SqlParameter()
                param10.ParameterName = "@Mobile"
                param10.Value = txtMobile.Text.Trim()
                cmd.Parameters.Add(param10)

                Dim param11 As New SqlParameter()
                param11.ParameterName = "@Email"
                param11.Value = txtEmail.Text.Trim()
                cmd.Parameters.Add(param11)

                cmd.Connection = cn
                cmd.ExecuteNonQuery()
                cn.Close()
            End Using
            Successlbl.Show()
            Successlbl.ForeColor = Color.DarkBlue
            Successlbl.Text = "Record Saved Successfully!."

        Catch
            Successlbl.Show()
            Successlbl.ForeColor = Color.Red
            Successlbl.Text = "Error in creating record!"
        End Try
    Else
        Try
            Dim connectionString As String = "Data Source=.\SqlExpress;Initial Catalog=Subscription;Integrated Security=True"
            Using cn As New SqlConnection(connectionString)
                cn.Open()
                cmd.CommandText = "UPDATE Customers SET (UserID, RegisteredDate, ExpiryDate, FirstName, LastName, Address, State, City, Phone, Mobile, Email) VALUES(@UserID, @RegisteredDate, @ExpiryDate, @FirstName, @LastName, @Address, @State, @City, @Phone, @Mobile, @Email) WHERE UserID=" & txtUserID.Text & ""

                Dim param1 As New SqlParameter()
                param1.ParameterName = "@UserID"
                param1.Value = txtUserID.Text.Trim()
                cmd.Parameters.Add(param1)

                Dim param2 As New SqlParameter()
                param2.ParameterName = "@RegisteredDate"
                param2.Value = RegisteredDate.Value
                cmd.Parameters.Add(param2)

                Dim param3 As New SqlParameter()
                param3.ParameterName = "@ExpiryDate"
                param3.Value = ExpiryDate.Value
                cmd.Parameters.Add(param3)

                Dim param4 As New SqlParameter()
                param4.ParameterName = "@FirstName"
                param4.Value = txtFirstName.Text.Trim()
                cmd.Parameters.Add(param4)

                Dim param5 As New SqlParameter()
                param5.ParameterName = "@LastName"
                param5.Value = txtLastName.Text.Trim()
                cmd.Parameters.Add(param5)


                Dim param6 As New SqlParameter()
                param6.ParameterName = "@Address"
                param6.Value = txtAddress.Text.Trim()
                cmd.Parameters.Add(param6)

                Dim param7 As New SqlParameter()
                param7.ParameterName = "@State"
                param7.Value = cboState.SelectedItem.ToString
                cmd.Parameters.Add(param7)

                Dim param8 As New SqlParameter()
                param8.ParameterName = "@City"
                param8.Value = cboCity.SelectedItem.ToString
                cmd.Parameters.Add(param8)

                Dim param9 As New SqlParameter()
                param9.ParameterName = "@Phone"
                param9.Value = txtPhone.Text.Trim()
                cmd.Parameters.Add(param9)

                Dim param10 As New SqlParameter()
                param10.ParameterName = "@Mobile"
                param10.Value = txtMobile.Text.Trim()
                cmd.Parameters.Add(param10)

                Dim param11 As New SqlParameter()
                param11.ParameterName = "@Email"
                param11.Value = txtEmail.Text.Trim()
                cmd.Parameters.Add(param11)

                cmd.Connection = cn
                cmd.ExecuteNonQuery()
            End Using
            Successlbl.Show()
            Successlbl.ForeColor = Color.DarkBlue
            Successlbl.Text = "Record updated Successfully!."

        Catch
            Successlbl.Show()
            Successlbl.ForeColor = Color.Red
            Successlbl.Text = "Error in updating record!"
        End Try
    End If

Can anyone say me where am I going wrong?

  • 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-18T02:16:01+00:00Added an answer on June 18, 2026 at 2:16 am

    Your UPDATE statement is all wrong for SQL Server / T-SQL. You cannot use the same syntax as the INSERT statement does. Read more about what the detailed syntax of UPDATE is on MSDN SQL Server Books Online.

    You need to specify:

    UPDATE dbo.Customers 
    SET 
       RegisteredDate = @RegisteredDate, 
       ExpiryDate = @ExpiryDate, 
       FirstName = @FirstName, 
       LastName = @LastName, ...... -- and so on for all relevant columns
    WHERE UserID = @UserID
    

    Also: you’re using parameters everywhere (+1 for that!), but not for the WHERE clause…. change that!

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

Sidebar

Related Questions

Im trying to update the contents of an element after running some php code.
I am trying to update some hibernate code that was written by someone else
Okay so I'm just trying to write some simple code that updates a record
UPDATE - New code at the bottom I'm trying to figure out how to
I'm trying to update some properties with KVC. The properties have been synthesized. This
Hi I am trying to update a div with some html from another div.
I'm trying to update the display brightness from a widget but i have some
i'm trying to make a ajax update in prototype with some values from a
I am trying to use drush to update my drupal core but in some
I am trying update text views while this loop is processing. Here is my

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.