|
-
Jan 6th, 2009, 08:12 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2008] Update query issue
I'm having an issue where this SQL statement isn't updating anything.
Code:
Using conn As New OleDbConnection(My.Settings.dcConn)
Using update As New OleDbCommand("UPDATE events SET title = @title WHERE event_id = @event_id", conn)
update.Parameters.AddWithValue("@event_id", ep.event_id)
update.Parameters.AddWithValue("@title", txtTitle.Text)
conn.Open()
Dim testNum As Integer
testNum = update.ExecuteNonQuery()
MessageBox.Show(testNum)
End Using
End Using
testNum returns "0" saying it affected no rows.
I get no errors with the Statement itself.
Other queries on the DB are working fine.
event_id is an Integer and is being populated with a valid ID.
Does anyone have any ideas why this might not be working?
Maybe you see something I'm doing wrong?
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jan 6th, 2009, 08:18 PM
#2
Re: [2008] Update query issue
Have you tried putting the Parameters in the order that they appear in the SQL statement. So basically switching your two AddWithValue lines around.
-
Jan 6th, 2009, 08:22 PM
#3
Thread Starter
Fanatic Member
Re: [2008] Update query issue
Thanks. That worked. Didn't know that mattered since the values have name identifiers and it's not like they are part of an array with only indexes.
Thanks a bunch. This has been messing me up for a long time.
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jan 6th, 2009, 08:25 PM
#4
Re: [2008] Update query issue
The only possible reason I can see is that there is no matching ID. Try retrieving a record using that ID just before updating and see if you get one.
-
Jan 6th, 2009, 08:34 PM
#5
Re: [RESOLVED] [2008] Update query issue
What database backend are you using? Each of them handle parameters a little differently.
-
Jan 6th, 2009, 08:39 PM
#6
Thread Starter
Fanatic Member
Re: [RESOLVED] [2008] Update query issue
Access
So it's Access actually handling it? not the SQL statement being "built" and then sent to Access?
Visual Studio 2010 Professional | .NET Framework 4.0 | Windows 7
SERYSOFT.COM :: SysPad - Folder Management Program - Please comment HERE if you find this program useful, have ideas, or know of any bugs.
[Very useful for IT/DP departments where many folders are consistently accessed. Also contains a scratchpad window for quick access to notes.]
[.NET and MySQL Quick Guide]
-
Jan 6th, 2009, 08:51 PM
#7
Re: [RESOLVED] [2008] Update query issue
I don't know all of the details of the oledb objects and how they work, as I usually use the SQL objects, so I can't say how they work with parameterized queries.
-
Jan 6th, 2009, 09:47 PM
#8
Re: [RESOLVED] [2008] Update query issue
Well spotted -0. Using parameter names with the Jet OLEDB provider is just a courtesy to make your code more readable. The names are actually ignored and, as you've experienced, it's just the order of the parameters that matters. The names you use in your SQL code and when you add parameters to the command don't have to have any relationship at all, but logic would dictate that they do, or else there's no point using names at all.
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
|