[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?
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.
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.
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.
Re: [RESOLVED] [2008] Update query issue
What database backend are you using? Each of them handle parameters a little differently.
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?
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.
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.