本文介绍了VB 中的 WHERE 语句.NET OleDB/SQL 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢您花时间看我的问题!我对这一切都很陌生,我正在尽最大努力找出解决方案,但我一直在碰壁.我正在尝试使用字符串的值更新 MDB 文件中的表,其中表的另一部分满足其他条件.我意识到调用字符串是不好的做法!
Thanks for taking the time to look at my question! I am new to all this and I am trying my best to work out the solution but I keep hitting a brick wall. I'm trying to update a table in a MDB file with the value of a String, where other conditions are met in another part of the table. I realise calling on strings is bad practise!
我认为问题出在 SQL 语句的 WHERE 部分?
I think the problem is with the WHERE part of the SQL statement?
感谢任何帮助,这是代码的一部分:
Appreciate any help, here is part of the code:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 'Declerations For Calling on Dim AnimalHouse As String AnimalHouse = "TestText" Dim AddressForAssingment As Integer AddressForAssingment = 1 Dim IDCheckAssignment As Integer IDCheckAssignment = 1 'Connection Information Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ProjectDirectory.Text) Dim myCommand As New OleDbCommand("INSERT INTO IOInformation SET Description= '" & AnimalHouse & "' WHERE ID_number= '" & AddressForAssingment & "' AND ID_Check= '" & IDCheckAssignment & "'") myCommand.Connection = myConnection myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close() End Sub 推荐答案像这样.请查看 参数化查询.
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 'Declerations For Calling on Dim AnimalHouse As String AnimalHouse = "TestText" Dim AddressForAssingment As Integer AddressForAssingment = 1 Dim IDCheckAssignment As Integer IDCheckAssignment = 1 'Connection Information Dim myConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ProjectDirectory.Text) Dim myCommand As New OleDbCommand("Update IOInformation SET [Description] = @animalHouse, WHERE ID_number = @addrForAssn AND ID_Check = @Id)) myCommand.Parameters.AddWithValue("@animalHouse", AnimalHouse) myCommand.Parameters.AddWithValue("@addrForAssn", AddressForAssingment) myCommand.Parameters.AddWithValue("@Id", IDCheckAssignment) myCommand.Connection = myConnection myConnection.Open() myCommand.ExecuteNonQuery() myConnection.Close()更多推荐
VB 中的 WHERE 语句.NET OleDB/SQL 查询
发布评论