我在这里有一些关于语法更新错误的问题 [英] I have some problem here about syntax update error

查看:85
本文介绍了我在这里有一些关于语法更新错误的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim sqlupdate As String =更新datasiswa set Name ='& TextBox2.Text& ',Alamat ='& TextBox3.Text& ',Kota ='& ComboBox1.Text& ',Provinsi ='& ComboBox2.Text& ',Jenis Kelamin ='& ComboBox3.Text& ',Umur ='& TextBox4.Text& ',Jurusan ='& ComboBox4.Text& ',Kelas ='& TextBox5.Text& ',其中NIS ='& TextBox1.Text& '

cmd =新OleDbCommand(sqlupdate,conn)

cmd.ExecuteNonQuery()

致电Tampil()

结束如果

结束如果

结束次级



我尝试过:



我试过检查但是仍然是同样的错误请帮助我

Dim sqlupdate As String = "Update datasiswa set Name='" & TextBox2.Text & "', Alamat='" & TextBox3.Text & "', Kota='" & ComboBox1.Text & "', Provinsi='" & ComboBox2.Text & "', Jenis Kelamin='" & ComboBox3.Text & "', Umur='" & TextBox4.Text & "', Jurusan='" & ComboBox4.Text & "', Kelas='" & TextBox5.Text & "', where NIS='" & TextBox1.Text & "'"
cmd = New OleDbCommand(sqlupdate, conn)
cmd.ExecuteNonQuery()
Call Tampil()
End If
End If
End Sub

What I have tried:

i've tried checking but still same error please help me

推荐答案

是的,大量的字符串连接是你遇到问题的原因,你也开始让自己的数据库被SQL注入攻击彻底摧毁。



谷歌为SQL注入找出你为什么做的事情是如此糟糕。



然后谷歌为VB.NET sql参数化查询找出如何解决这个问题。它还具有修复UPDATE语句问题的效果,使代码更容易调试和支持。



首先,这个令人厌恶:

Yeah, that massive pile of string concatenation is why you're having a problem and you've also opened yourself up to having your database completely destroyed by an SQL Injection attack.

Google for "SQL Injection" to find out why what you're doing is so bad.

Then Google for "VB.NET sql parameterized queries" to find out how to fix this. It will also have the effect of fixing your UPDATE statement problem and make your code far easier to debug and support.

To start, this abomination:
"Update datasiswa set Name='" & TextBox2.Text & "', Alamat='" & TextBox3.Text & "', Kota='" & ComboBox1.Text & "', Provinsi='" & ComboBox2.Text & "', Jenis Kelamin='" & ComboBox3.Text & "', Umur='" & TextBox4.Text & "', Jurusan='" & ComboBox4.Text & "', Kelas='" & TextBox5.Text & "', where NIS='" & TextBox1.Text & "'"



成为:


becomes this:

"UPDATE datasiswa SET Name=@Name, Alamat=@Alamat, Kota=@Kota, Provinsi=@Provinsi, [Jenis Kelamin]=@Jenis, Umur=@Umur, Jurusan=@Jurusan, Kelas=@Kelas WHERE NIS=@NIS"



哦,在表名和列名中加入空格并不是一个好主意。如果你这样做,它们很多都用方括号括起来。只是避免将空格放在那里开始,让生活更轻松。


Oh, and it's not a good idea to have spaces in table and column names. If you do, they much be enclosed in square brackets. Just avoid putting the spaces in there to begin with and make your life easier.


Dim sqlupdate As String = "Update datasiswa set Name='" & TextBox2.Text & "', Alamat='" & TextBox3.Text & "', Kota='" & ComboBox1.Text & "', Provinsi='" & ComboBox2.Text & "', Jenis Kelamin='" & ComboBox3.Text & "', Umur='" & TextBox4.Text & "', Jurusan='" & ComboBox4.Text & "', Kelas='" & TextBox5.Text & "', where NIS='" & TextBox1.Text & "'"



永远不要构建SQL通过连接字符串进行查询。迟早,您将使用用户输入来执行此操作,这会打开一个名为SQL注入的漏洞,这对您的数据库很容易并且容易出错。

名称中的单引号你的程序崩溃。如果用户输入像Brian O'Conner这样的名称可能会使您的应用程序崩溃,那么这是一个SQL注入漏洞,崩溃是最少的问题,恶意用户输入,并且它被提升为具有所有凭据的SQL命令。

SQL注入 - 维基百科 [ ^ ]

SQL注入 [ ^ ]

按示例进行SQL注入攻击 [ ^ ]

PHP:SQL注入 - 手册 [ ^ ]

SQL注入预防备忘单 - OWASP [ ^ ]

我该怎么办?解释没有技术术语的SQL注入? - 信息安全堆栈交换 [ ^ ]


Never build an SQL query by concatenating strings. Sooner or later, you will do it with user inputs, and this opens door to a vulnerability named "SQL injection", it is dangerous for your database and error prone.
A single quote in a name and your program crash. If a user input a name like "Brian O'Conner" can crash your app, it is an SQL injection vulnerability, and the crash is the least of the problems, a malicious user input and it is promoted to SQL commands with all credentials.
SQL injection - Wikipedia[^]
SQL Injection[^]
SQL Injection Attacks by Example[^]
PHP: SQL Injection - Manual[^]
SQL Injection Prevention Cheat Sheet - OWASP[^]
How can I explain SQL injection without technical jargon? - Information Security Stack Exchange[^]


这篇关于我在这里有一些关于语法更新错误的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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