Results 1 to 8 of 8

Thread: [RESOLVED] [2008] Update query issue

  1. #1

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    Resolved [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]

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  3. #3

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: [RESOLVED] [2008] Update query issue

    What database backend are you using? Each of them handle parameters a little differently.

  6. #6

    Thread Starter
    Fanatic Member Seraph's Avatar
    Join Date
    Jul 2007
    Posts
    959

    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]

  7. #7
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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