Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to update a record in table..
When I try to update in access database through query it works fine but does not updates through vb.net.
Here is the code i wrote:
sql = Update VILLAGEMST set VCODE = 2 where TADDRESS like '*txtVilName.Text*' &
MainCon.Execute(sql)
MsgBox(Updated.)
Posted
Comments
Divya RS 12-Nov-12 1:59am    
use a try and catch blocks so that u can find exceptions if any , also go with breakpoint, u cant solve ur issue unless u know where the exact problem is....

1 solution

sql = Update VILLAGEMST set VCODE = 2 where TADDRESS like '*txtVilName.Text*' &


This code is meaningless. You're treating the txtVilName.Text as if it were automatically replaced in strings where it is mentioned. It doesn't work that way.

I highly suggest you pickup a beginners book on VB.NET and work through it. Your making a very basic mistake because you don't undertand simple string manipulations.

Change it to this:
sql = Update VILLAGEMST set VCODE = 2 where TADDRESS like '%' & txtVilName.Text & "'"

Also, this is horribly bad SQL as you're leaving yourself open to SQL Injection attacks. I suggest Googling for "SQL Injection Attacks" and "VB.NET SQL Parameterized queries" to read up on what that is and what to do about it.
 
Share this answer
 

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