Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am using VB6 and DAO connnection with Access.

I want to update the records in access using VB. The column name and comments to be updated will be provided by user in text box. Please provide me the SQL command for the same.

I tried below but not working

"UPDATE Sheet1 SET '"&text6.text&"'='"&text47.Text&"'Where Vertical = '" & Combo1.text & "'"
Posted
Updated 5-May-15 21:25pm
v2
Comments
Arkadeep De 6-May-15 3:31am    
try this one...
"UPDATE Sheet1 SET '"&text6.text&"'='"&text47.Text&"' Where Vertical = '" & Combo1.text & "'"
I have just add an extra space before where. May be you are getting an error for this...if not then share what exactly the error is.
Gaus Shaikh 6-May-15 3:58am    
Getting an error, Expected end of statement
Gaus Shaikh 6-May-15 4:05am    
Please assist. I am getting error - Expected end of statment
Gaus Shaikh 6-May-15 4:10am    
Please response
Gaus Shaikh 6-May-15 4:27am    
Aany update

1 solution

That is a very dangerous thing to do: you leave yourself wide open to SQL Injection.
Never concatenate strings to form an SQL command: it's far, far too easy for the user to type SQL commands in the text box and damage or destroy your database. Always use parameterised queries. Google "Bobby tables" and you'll see what I mean...

And the direct cause of your problem is almost certainly the quotes round column name: they indicate a string to SQL so you are effectively telling it to set a string to another string, which isn't going to work.

BTW: Do yourself a favour, and stop using Visual Studio default names for everything - you may remember that "TextBox47" is the mobile number today, but when you have to modify it is three weeks time, will you then? Use descriptive names - "tbMobileNo" for example - and your code becomes easier to read, more self documenting, easier to maintain - and surprisingly quicker to code because Intellisense can get to to "tbMobile" in three keystrokes, where "TextBox47" takes thinking about and 9 keystrokes...
 
Share this answer
 
Comments
Gaus Shaikh 6-May-15 4:06am    
What is wrong in below query. It is showing expect end of statment.....
"UPDATE Sheet1 SET '"&text6.text&"' = '"&text47.Text&"' Where Vertical = '" & Combo1.text & "'"
Gaus Shaikh 6-May-15 4:10am    
Please assist
OriginalGriff 6-May-15 4:18am    
Read what I said?
Gaus Shaikh 6-May-15 4:25am    
Thanks for response. I have changed the default name but still getting errro - " Expect end of statment". Please assist

"UPDATE Sheet1 SET '"Date1&"' = '"&data1&"' Where Vertical = '" & Combo1.text & "'"
OriginalGriff 6-May-15 4:35am    
Tell me, are you thinking about what you are doing, or just guessing and hoping it will work?
Because if you look at the line of code and SQL you just posted...

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