954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Sql UPDATE Not working

Hi all

With the following SQL " Dim Query As String = "UPDATE JobName_tbl SET [JobDate]=@NewDATE, JobAddress=@Newaddress Where JobID=@ID"
nothing happens nothing gets updated nor do I get an error.
But as soon as I remove the [JobDate]=@NewDATE, it works fine.
Hope someone can help me with this situation.
Here is my code:
Thank You

Public Sub UpdateAddress(ByVal JobID As Integer, ByVal JobUpdate As String, ByVal NewDate As Date)
        Try            
            Dim Query As String = "UPDATE JobName_tbl SET [JobDate]=@NewDATE, JobAddress=@Newaddress Where JobID=@ID"    
            Dim DBcon As New DBConnection.Connection
            DBcon.FilePath = "C:\CFI\Filepath.txt"
            DBcon.connect()
            DBcon.con.Open()
           Dim cmd As New OleDb.OleDbCommand(Query, DBcon.con)
                With cmd
                .CommandType = CommandType.Text
                .CommandText = Query
                .Parameters.AddWithValue("@Newaddress", JobUpdate)
                .Parameters.AddWithValue("@ID", JobID)
                .Parameters.AddWithValue("@NewDATE", NewDate)
                .ExecuteNonQuery()
            End With
            DBcon.con.Close()
        Catch ex As Exception
            MsgBox("JobAddress_UpdateAddress" & ex.Message)
        End Try
    End Sub
VIPER5646
Junior Poster in Training
84 posts since Mar 2009
Reputation Points: 10
Solved Threads: 2
 

What happens if you just remove the brackets from JobDate [] ?

thines01
Postaholic
Team Colleague
2,425 posts since Oct 2009
Reputation Points: 445
Solved Threads: 402
 

A good step in debugging something like this is to get the actual statement and either run it in the db or at least go through it.

use debug.print cmd.commandtext just before the ExecuteNonQuery and verify that you are running what you think you are.

adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 

A good step in debugging something like this is to get the actual statement and either run it in the db or at least go through it.

use debug.print cmd.commandtext just before the ExecuteNonQuery and verify that you are running what you think you are.

Thanks All for your help but I solved it by putting the .Parameters.AddWithValue in the same order as in the query.
:)

VIPER5646
Junior Poster in Training
84 posts since Mar 2009
Reputation Points: 10
Solved Threads: 2
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You