CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2012
    Posts
    6

    Problem with parameterized update query

    I am using the following code to try and update a database entry, the UPDATE statement works when i am not using parameters but when i am using them it seems to do absolutely nothing. No error and no update either.

    PHP Code:
    sqlString "UPDATE table SET field1 = @value1, field2 = @value2, field3 = @value3 WHERE field1 = @currentValue" 
     
    dbCommand.CommandText sqlString 
    dbCommand
    .Parameters.AddWithValue("@value1"txtOne.Text
    dbCommand.Parameters.AddWithValue("@field2 "txtTwo.Text
    dbCommand.Parameters.AddWithValue("@field3 "txtThree.Text
    dbCommand.Parameters.AddWithValue("@currentValue"lstListBox.SelectedValue
    dbCommand.ExecuteNonQuery() 
    Can anyone tell me why this isnt working?

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Problem with parameterized update query

    you've missed matched the parameter names...

    field1 = @value1, field2 = @value2, field3 = @value3

    and then..

    dbCommand.Parameters.AddWithValue("@value1", txtOne.Text)
    dbCommand.Parameters.AddWithValue("@field2", txtTwo.Text)
    dbCommand.Parameters.AddWithValue("@field3", txtThree.Text)


    Also take the space out of the parameters name....
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

  3. #3
    Join Date
    Dec 2012
    Posts
    6

    Re: Problem with parameterized update query

    Actually that was just a mistake when i was posting the code, i changed the parameter names from what i actually have in my code and accidentally put @field instead of @value. In my code they are actually correct. That wasnt the source of the problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured