且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新数据库时出现问题

更新时间:2021-11-30 09:43:04

首先,不要直接连接值到SQL语句。这使您可以完全接受SQL注入。而是使用 SqlParameter [ ^ ]。



然后你不需要适配器。简单地说:

First of all, do not ever concatenate values directly to the SQL statement. This leaves you wide open to SQL injections. Instead use SqlParameter[^].

Then you don't need the adapter. Simply:
Dim con As New SqlConnection("Data Source=CSC32\SQLEXPRESS;Initial Catalog=Data1;Integrated Security=True;")
con.Open()
Dim cmd As New SqlCommand("update Logs set Email=@email, DOB=@dob, Secques=@Secques,Secans=@Secans where Username=@username", con)
' SET PARAMETER VALUES OVER HERE
...
cmd.Parameters.AddWithValue("@Secques", sqtext.Text)
...

cmd.ExecuteNonQuery()
con.Close()





另外

- 使用调试器ch在将文本分配到参数时,确实使用了最新值。

- 建议使用使用 [ ^ ]连接语句

- 更好的是将DML操作包装在 SqlTransaction [ ^ ]



Also
- using debugger check that you really use the latest values when assigning the text into parameters.
- it's advisable to use using[^] statement for the connection
- and better yet wrap the DML operations inside a SqlTransaction[^]


我可以猜到它,直到你提供一些代码。

检查在插入数据时是否为某个变量赋值,如果编辑数据,则不会为同一变量分配更新值。
I can guess it untill you provide some code.
Check if you have assigned value in some variable while inserting data and the same variable is not assigned with updated value in case if editing data.