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

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 & "'"

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.

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 & "'"

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

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.