问题描述
我正在尝试更新表中的记录..
当我尝试通过查询在Access数据库中更新时,它工作正常,但无法通过vb.net更新.
这是我写的代码:
sql =更新VILLAGEMST设置VCODE = 2其中TADDRESS如``* txtVilName.Text *''&
MainCon.Execute(sql)
MsgBox(已更新.)
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.)
推荐答案
sql = Update VILLAGEMST set VCODE = 2 where TADDRESS like ''*txtVilName.Text*'' &
此代码是没有意义的.您正在对待txtVilName.Text,就好像它被自动替换为提到的字符串一样.那样行不通.
我强烈建议您在VB.NET上阅读一本初学者的书并进行学习.您犯了一个非常基本的错误,因为您不了解简单的字符串操作.
更改为此:
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 & "''"
而且,这是非常糟糕的SQL,因为您不愿接受SQL注入攻击.我建议谷歌搜索"SQL注入攻击"和"VB.NET SQL参数化查询",以了解其含义和处理方法.
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.
这篇关于通过vb.net无法更新db中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!