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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:57:29+00:00 2026-06-14T07:57:29+00:00

Is it possible to us my existing INSERT code and have it do the

  • 0

Is it possible to us my existing INSERT code and have it do the same thing but UPDATE?

Example would be:

ID  | formTitle1 | formTitle2 | formTitle3 | formTitle4
-------------------------------------------------------
20  | The Rock   | Booker     | The Vine   | Keys

if i wanted to update all 4 of those rows then i think i could do it like this?:

sql = "UPDATE formSettings " & _
      "SET (formTitle1, formTitle2, formTitle3, formTitle4) " & _
      "VALUES (@formTitle1, @formTitle2, @formTitle3, @formTitle4) " & _
      "WHERE ID = '" & theID & "'"

Dim updateCmd As New SqlCommand(sql, myCONN)
updateCmd.Parameters.Add("@formTitle1", SqlDbType.VarChar)
updateCmd.Parameters.Add("@formTitle2", SqlDbType.VarChar)
updateCmd.Parameters.Add("@formTitle3", SqlDbType.VarChar)
updateCmd.Parameters.Add("@formTitle4", SqlDbType.VarChar)

updateCmd.Parameters("@formTitle1").Value = "changed1"
updateCmd.Parameters("@formTitle2").Value = "changed2"
updateCmd.Parameters("@formTitle3").Value = "changed3"
updateCmd.Parameters("@formTitle4").Value = "changed4"

myCONN.Open()
updateCmd.ExecuteScalar()
myCONN.Close()

Should update to:

ID  | formTitle1 | formTitle2 | formTitle3 | formTitle4
-------------------------------------------------------
20  | changed1   | changed2   | changed3   | changed4

I know i have the wrong UPDATE syntax but i am unsure if this is even possible?

  • 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-14T07:57:30+00:00Added an answer on June 14, 2026 at 7:57 am

    you have invalid syntax for update, it should be

    sql = "UPDATE formSettings " & _
          "SET formTitle1 = @formTitle1, formTitle2 = @formTitle2, formTitle3 = @formTitle3, formTitle4 = @formTitle4 " & _
          "WHERE ID = @ID"
    

    and parameterized also your ID and you will now have 5 parameters

    also restructure your code into this,

    • using USING statement
    • adding exception handling

    snippet,

    Dim _sql As String = "UPDATE formSettings " & _
          "SET formTitle1 = @formTitle1, formTitle2 = @formTitle2, formTitle3 = @formTitle3, formTitle4 = @formTitle4 " & _
          "WHERE ID = @ID" 
    Using conn As New SqlConnection("connectionStringHere")
        Using comm As New SqlCommand()
            With comm
                .Connection = conn
                .CommandType = CommandType.Text
                .CommandText = _sql
                .Parameters.AddWithValue("@formTitle1", "changed1")
                .Parameters.AddWithValue("@formTitle2", "changed2")
                .Parameters.AddWithValue("@formTitle3", "changed3")
                .Parameters.AddWithValue("@formTitle4", "changed4")
                .Parameters.AddWithValue("@ID", theID)
            End With
            Try
                conn.Open()
                comm.ExecuteNonQuery()
            Catch ex As SqlException
                ' do something on the error
                ' do not hide it!
            End Try
        End Using
    End Using
    

    SOURCES

    • AddWithValue
    • Add (recommended to use)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: insert contacts into database but does not want to duplicate already existing
Possible Duplicate: insert contacts into database but does not want to duplicate already existing
Possible Duplicate: Adding members to an existing object Lets say you have the following
With nio it is possible to map an existing file in memory. But is
So I have an existing ASP.NET solution that uses LINQ-to-SQL to insert data into
I have an existing REST application on my server. For example, if you send
I'm using the following code to insert a new entry in my existing db.
I have some existing code in C# that I'm trying to move to an
Possible Duplicate: Using Git with an existing Xcode project Setting up a git repository
is it possible to change the Audience of an already existing Post in 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.