-
December 12th, 2012, 07:21 PM
#1
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?
-
December 13th, 2012, 12:53 AM
#2
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.
-
December 14th, 2012, 03:13 PM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|