Click here to Skip to main content
16,019,876 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
can some pls advise me how i can add multiple where conditions in database when updated it
i try to use below code but its not successful and appear Syntax error (Missing operator )in query expression

VB
SavInto1.CommandText = "UPDATE PrintDetails set BaseFabricColor=" & "'" & TextBox3.Text & "'" & ",ArtWorkRef = " & "'" & TextBox4.Text & "'" & " WHERE OrderNo =" & "'" & TextBox1.Text & " AND PrintOn=" & "'" & TextBox2.Text & " '"
Posted

1 solution

The immediate problem is that you have missed out a quote:
VB
SavInto1.CommandText = "UPDATE PrintDetails set BaseFabricColor=" & "'" & TextBox3.Text & "'" & ",ArtWorkRef = " & "'" & TextBox4.Text & "'" & " WHERE OrderNo =" & "'" & TextBox1.Text & " AND PrintOn=" & "'" & TextBox2.Text & " '"
Should be
VB
SavInto1.CommandText = "UPDATE PrintDetails set BaseFabricColor='" & TextBox3.Text & "', ArtWorkRef = '" & TextBox4.Text & "' WHERE OrderNo ='" & TextBox1.Text & "' AND PrintOn='" & TextBox2.Text & "'"

But please don't do it like that!
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
 
Share this answer
 
Comments
Ahmed Shafea 1-Oct-13 12:13pm    
thanks too much... your code had worked with me ... i will looking forward for learn how usage of the Parametrized ...
Richard C Bishop 1-Oct-13 12:21pm    
Was that painful to post? :)
OriginalGriff 1-Oct-13 12:25pm    
Yep. But I hate doing VB code when I have no idea how the user is implementing his update code - there are so many ways to do it SQLCommand, SqlDataAdapter, etc., that I don't like to confuse people too much. :laugh:
Richard C Bishop 1-Oct-13 12:29pm    
I hear that. It is helpful in some instances to do as you did. +5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900