VB.NET更新MS访问表 [英] VB.NET UPDATE MS ACCESS TABLE

查看:90
本文介绍了VB.NET更新MS访问表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的更新代码,但是我的表记录从不更新

Here is my Update code, but my table records never update

Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUpdate.Click
       If txtbookID.Text <> "" And txtauthor.Text <> "" Then
           updater.CommandText = "UPDATE books SET Author = '" & txtauthor.Text & "' WHERE bookId = " & txtbookID.Text & ";"
           
           updater.CommandType = CommandType.Text
           updater.Connection = conn
           updater.ExecuteNonQuery()
           MsgBox("Record updated.")


       Else
           MessageBox.Show("Please enter the data into the required fields", "Update Error!")
       End If
       updater.Dispose()

   End Sub




不知道出什么问题了.请尽快帮助我.




Dont know what is wrong. please help me as soon as possible.

推荐答案

首先,您应该阅读有关SQL注入攻击的信息,以了解为什么这是错误的代码.请我输入一本书,然后我就可以擦除您的数据库.其次,您是否使用调试器查看此代码是否被调用?您的作者或书号中是否包含任何"字符?这将破坏SQL(使用参数化查询的另一个原因).

此处 [
First of all you should read up on SQL injection attacks to see why this is bad code. Ask me to enter a book, and I can erase your DB. Secondly, did you use the debugger to see if this code is called ? Are there any '' characters in your author or book id ? This will break the SQL ( another reason to use paramaterised queries ).

Here[^] is an answer that shows how to do this properly. I suggest you fix this code, then see if you still have an issue. If you do, use your debugger to work out what is going on, then ask us if you''re still stuck.


这篇关于VB.NET更新MS访问表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆