Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
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 11-Nov-12 18:56pm
Comments
Anusha SR at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100