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

Not Working Update Command

Hi Everyone,
I am currently Working on a School Project which has the form of a stock update System. I am using an access 2007 DB and building my code in Visual Studio 2010. I am trying to get an Update Query to work and I am completely unsure on how to go about it.... Here is what I have so far.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As New OleDbConnection
        Dim cmd As New OleDbCommand
        Dim Query As String

        Query = "update Prod_DB_Laminate_Raw set [Stock Level] = '" & TextBox1.Text & "where Laminate = " & ComboBox1.Text & ""
      
        con.Open()
        cmd = New OleDbCommand(Query, con)
        cmd.ExecuteNonQuery()
        cmd.Dispose()
        con.Close()

    End Sub


Is this the correct way of doing this or am I looking at the wrong thing entirely?

Many Thanks
Ziggy

Ziggy713
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Put a space between the quote and the word where
" where

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

When I do that, it then throws this error at me:
Syntax error in string in query expression '456 where Laminate = Mahogany'.
How do I solve this?

Ziggy713
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

Change it to

Query = "update Prod_DB_Laminate_Raw set [Stock Level] = '" & TextBox1.Text & "' where Laminate = '" & ComboBox1.Text & "'"

Wnen you run into a problem like this it is best to display the actual query string as submitted to SQL. In most cases the error will be obvious. An extra line of

msgbox(Query)

Can open your eyes.

Reverend Jim
Posting Shark
Moderator
1,167 posts since Aug 2010
Reputation Points: 253
Solved Threads: 159
 

Thank You Very Much Reverend, I'm still pretty new at this, just trying to find my way

Ziggy713
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: