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

Multiple WHERE Conditions, SQL Update

Hi Everyone,
I'm doing a stock Control System as a school Project using An Access 2007 DB and Visual Studio 2010. I'm trying to do an update Query based on two variables entered into comboboxes, I cannot get the VB to accept the conditions for this, Can anyone Help me?
Here is my Code

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "AND" & "'" ComboBox3.Text & "'"
        Dim cmd As New OleDbCommand
        con.Open()
        cmd = New OleDbCommand(Query, con)
        cmd.ExecuteNonQuery()
        MsgBox("Stock Updated Successfully", MsgBoxStyle.Information)
        cmd.Dispose()
        con.Close()
        ComboBox2.Text = ""
        ComboBox3.Text = ""
        TextBox2.Text = ""
    End Sub

I Cannot get the Code to recognise the Last "'", is there a way to do this?

Many Thanks

Ziggy

Ziggy713
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 
Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "AND" & "'" ComboBox3.Text & "'"

Missing Other Column Name :

"AND OtherColumName = " & "'" ComboBox3.Text & "'"
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

Are you getting a syntax error? I think it is because you aren't using the WHERE clause correctly. You need to have:

WHERE Laminate = '" & ComboBox2.Text & "'" & "AND WHERE <another column> = " & "'" ComboBox3.Text & "'"

By missing that second column you are saying "WHERE laminate = some_text AND some_other_text.

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 167
 

Okay, I implemented the changes that you suggested, and VS 2010 now tells me that it is expecting an end of statement at the

combobox3.text & "'"


I don't understand what it means.....

This is the update Query with the changes in it

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "and where [Board Size] = " & "'" ComboBox3.Text & "'"
Ziggy713
Newbie Poster
9 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

hello !
use this

"update Prod_DB_Completed_Board set Stock Level = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "' and Board Size = '" & ComboBox3.Text & "'"


It will work fine :) if your prob is solved please mark this thread solved :)

Regards

M.Waqas Aslam

waqasaslammmeo
Posting Pro in Training
472 posts since Aug 2011
Reputation Points: 38
Solved Threads: 82
 

Okay, I implemented the changes that you suggested, and VS 2010 now tells me that it is expecting an end of statement at the

combobox3.text & "'"

I don't understand what it means.....

This is the update Query with the changes in it

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "'" & "and where [Board Size] = " & "'" ComboBox3.Text & "'"

No need to add the where twice

Query = "update Prod_DB_Completed_Board set [Stock Level] = '" & TextBox2.Text & "' where Laminate = '" & ComboBox2.Text & "' and  [Board Size] = '" & ComboBox3.Text & "'"


This will help u

poojavb
Posting Whiz
324 posts since Nov 2011
Reputation Points: 31
Solved Threads: 37
 

Thank you very much M.Waqas Aslam, thats fixed the problem for me :)

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

this is not fair , i try to solve the prob and some body give me negative vote :( ,

waqasaslammmeo
Posting Pro in Training
472 posts since Aug 2011
Reputation Points: 38
Solved Threads: 82
 

This question has already been solved

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