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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:09:45+00:00 2026-06-14T12:09:45+00:00

I am trying to write a paramaterized update query to insert values into an

  • 0

I am trying to write a paramaterized update query to insert values into an Sql Server Express Database. The query I have written is:

Dim cmd As New SqlCommand
cmd.Connection = conn
cmd.CommandText = "update tblposts set title=@ptitle, pdate=@pd, 
                   content=@pcontent where pid=@p"
cmd.Parameters.AddWithValue("ptitle", txtTitle.Text)
cmd.Parameters.AddWithValue("pcontent", txtcontent.InnerText)
cmd.Parameters.AddWithValue("pd", DateTime.Now.ToString)
cmd.Parameters.AddWithValue("p", postid)

On running cmd.ExecuteNonQuery, I get number of rows affected as 1, but the change is not reflected in the database.

On printing the query using Debug.Write, I get the query not with the parameter values, but the names of the parameters itself (ie. @pcontent, @title etc)

What can be the mistake here?

  • 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-14T12:09:46+00:00Added an answer on June 14, 2026 at 12:09 pm

    In you’re AddWithValue you need to include the @ symbol on the front of the parameter, so:

    cmd.Parameters.AddWithValue("@ptitle", txtTitle.Text)
    cmd.Parameters.AddWithValue("@pcontent", txtcontent.InnerText)
    cmd.Parameters.AddWithValue("@pd", DateTime.Now.ToString)
    cmd.Parameters.AddWithValue("@p", postid)
    

    I’m guessing that it’s executing correctly but there where clause is blank, so perhaps updating a blank row.

    Anyway, try the above and it should update as expected.

    Edit to Add

    The CommandText will always only have the @value in there, it will not substitue the parameter values into the string.

    You would need to loop through the cmd.Parameters collection to write out the values.

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

Sidebar

Related Questions

I'm trying write a query to find records which don't have a matching record
Trying to write a trivial application, But I have stuck into one of the
I am trying write a SQL query that filters a gridview by the fields
I'm trying write a routine in SQL Server that, when run, would traverse specified
Trying to write a javascript bookmarklet to jump from a front end link into
Trying to write a windows speech recognition macro. Written using XML and scripting language
Trying to write a tomcat application. Well learning how. Its written in JSP. No
We've been trying write unit tests for a worker class written in C#, which
I have been trying write a Mutually Exclusive CheckBox. There are two checkBoxes in
I am trying write a query that will display if the person has anyone

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.