【发布时间】:2020-04-08 06:16:30
【问题描述】:
这是我的 OLEDB DB 选择和更新代码。
我在更改密码字段值时遇到条件表达式中的数据类型不匹配错误。
所有四个字段都设置为长文本数据类型。
更新查询
con = Class1.dbconn
cmd = New OleDbCommand("Update User_details set User_ID ='" & TextBox1.Text & "', User_Name='" & TextBox2.Text & "', [Password]='" & TextBox3.Text & "' where Sno='" & Label4.Text & "'", con)
cmd.ExecuteNonQuery()
MessageBox.Show("User Details Updated")
选择查询
cmd = New OleDbCommand("select * from User_details where User_ID='" & TextBox1.Text & "'", con)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader
If dr.Read Then
Label4.Text = dr("Sno").ToString
TextBox2.Text = dr("User_Name").ToString
TextBox3.Text = dr("Password").ToString
TextBox2.Text = TextBox2.Text.Replace(" ", "")
TextBox3.Text = TextBox3.Text.Replace(" ", "")
dr.Close()
End If
【问题讨论】:
-
什么是
Longtext?你的意思是Memo?使用参数构建查询 (OleDbCommand.Parameters.Add())。另请参阅INFO: OleDbType Enumeration vs. Microsoft Access Data Types。 -
向我们展示您的表创建语句。如果使用 Sql Server Management Studio,右键单击该表并选择 Script table as create 到 New Window。此外,正如@Jimi 所说,您应该考虑使用参数而不是内联 sql。此代码对 sql 注入攻击开放。如果这只是为了学习,好吧。搞定后,去学习正确的方法。你永远不应该在生产应用程序中这样做。
标签: sql vb.net ms-access oledb